Best JavaScript code snippet using wpt
index.js
Source:index.js
1//Exercicio 12/*const respostaDoUsuario = prompt("Digite o número que você quer testar?")3const numero = Number(respostaDoUsuario)4if(numero % 2 === 0) {5 console.log("Passou no teste.")6} else {7 console.log("Não passou no teste.")}*/8//R= Este teste realiza uma divisão do numero digitado pelo usuário por 2.9//R= Imprime numeros pares, pois esses números ao serem divididos por dois não tem nenhum resto.10//R= Para números impares, pois são aprovados apenas números que não deixam resto ao serem divididos por 2.11//Exercicio212/*let fruta = prompt("Escolha uma fruta")13let preco14switch (fruta) {15 case "Laranja":16 preco = 3.517 break;18 case "Maçã":19 preco = 2.2520 break;21 case "Uva":22 preco = 0.3023 break;24 case "Pêra":25 preco = 5.526 break; // BREAK PARA O ITEM d.27 default:28 preco = 529 break;30}31console.log("O preço da fruta ", fruta, " é ", "R$ ", preco)*/32//a)R= Para o usuário vizualizar o preço da fruta que ele selecionou.33//b)R= O preço que aparecerá será de 2.25.34//c)R= 24.55.35//d)R= O valor da Pêra fica de 5.36//ExercÃcio 337/*const numero1 = prompt("Digite o primeiro número.")38const numero2 = prompt("Digite o próximo número?")39if(numero1 > 0 && numero2 > 0) {40 let mensagem41 if(numero1 > numero2) {42 mensagem = "Número 1 é maior que o 2!"43 } else {44 mensagem = "Número 1 é menor ou igual ao 2!"45 }46}47console.log(mensagem)*/48//R= Dá erro, pois o comando console não consegue ler as o valor das variaveis nos blocos.49//-----Exercicios de código-----//50//Exercicio 451//a) R= Não acontecia nada52/*let numberOne = Number(prompt("Digite o primeiro número:"))53let numberTwo = Number(prompt("Digite um segundo número:"))54if(numberOne > numberTwo){55 console.log(numberOne,numberTwo)56} else if(numberOne < numberTwo){57 console.log(numberTwo,numberOne) // R= Não acontecia nada quando colocava números iguais 58}*/59//b)60/*let numberOne = Number(prompt("Digite o primeiro número:"))61let numberTwo = Number(prompt("Digite um segundo número:"))62let numberTree = Number(prompt("Digite um terceiro número:"))63if((numberOne > numberTwo) && (numberTwo > numberTree)){64 console.log(numberOne,numberTwo,numberTree)65} else if((numberOne < numberTwo) && (numberOne > numberTree)){66 console.log(numberTwo,numberOne,numberTree) 67} else if((numberTree > numberOne) && (numberOne > numberTwo)){68 console.log(numberTree,numberOne,numberTwo) 69} else if((numberTree > numberTwo) && (numberTwo > numberOne)){70 console.log(numberTree,numberTwo,numberOne)71} else if((numberTwo > numberTree) && (numberTree > numberOne)){72 console.log(numberTwo,numberTree,numberOne)73} else if((numberOne > numberTwo) && (numberTwo < numberTree)){74 console.log(numberOne,numberTree,numberTwo) //Não acontece nada75}*/76//c)77/*let numberOne = Number(prompt("Digite o primeiro número:"))78let numberTwo = Number(prompt("Digite um segundo número:"))79let numberTree = Number(prompt("Digite um terceiro número:"))80if((numberOne > numberTwo) && (numberTwo > numberTree)){81 console.log(numberOne,numberTwo,numberTree)82} else if((numberOne < numberTwo) && (numberOne > numberTree)){83 console.log(numberTwo,numberOne,numberTree) 84} else if((numberTree > numberOne) && (numberOne > numberTwo)){85 console.log(numberTree,numberOne,numberTwo) 86} else if((numberTree > numberTwo) && (numberTwo > numberOne)){87 console.log(numberTree,numberTwo,numberOne)88} else if((numberTwo > numberTree) && (numberTree > numberOne)){89 console.log(numberTwo,numberTree,numberOne)90} else if((numberOne > numberTwo) && (numberTwo < numberTree)){91 console.log(numberOne,numberTree,numberTwo)92}else{93 console.log("Os números digitados foram iguais, digite ao menos um número diferente")94}*/95//Exercicio 596let animal = prompt("Digite o nome do animal")97let espinha = prompt("Esse animal é vertebrado?")98switch(espinha){99 case"sim":100 let pelo = prompt("Esse animal possuiu pelos?")101 switch(pelo){102 case"sim":103 let mamifero = prompt("Esse animal é um mamifero?")104 switch(mamifero){105 case"sim":106 let tipo = prompt("Esse mamifero é racional?")107 switch(tipo){108 case"sim":109 console.log("Seu animal é o Ser Humano")110 }111 break112 case"não":113 console.log("Seu animal é um mamifero não racional!")114 }115 break116 case"não":117 let penas = prompt("Esse animal possui penas?")118 switch(penas){119 case"sim":120 console.log("Seu animal é uma ave!")121 break122 case"não":123 let terra = prompt("Seu animal é um animal terrestre?")124 switch(terra){125 case"sim":126 let anfibio = prompt("Seu animal passa parte de sua vida na água?")127 switch(anfibio){128 case"sim":129 console.log("Seu animal é um anfibio!")130 break131 case"não":132 console.log("Seu animal é um réptil!")133 }134 break135 case"não":136 console.log("Seu animal é um peixe!")137 }138 }139 }140 break141 case"não":142 console.log("Seu animal é um invertebrado!")...
search.ts
Source:search.ts
1import { TreeNode } from '../../datastructure/Node'2type NumberTree = TreeNode<number> | null3/**4 * @description 广度ä¼å
æç´¢5 */6const bfs = (root: NumberTree) => {7 const result: number[] = []8 const queue: NumberTree[] = []9 queue.push(root)10 while (queue.length !== 0) {11 const node = queue.shift()12 if (node) {13 result.push(node.value)14 if (node.left) queue.push(node.left)15 if (node.right) queue.push(node.right)16 }17 }18 return result19}20/**21 * @description 深度ä¼å
æç´¢22 */23const dfs = (root: NumberTree) => {24 const result: number[] = []25 const stack: NumberTree[] = []26 stack.push(root)27 while (stack.length !== 0) {28 const node = stack.pop()29 if (node) {30 result.push(node.value)31 if (node.right) stack.push(node.right)32 if (node.left) stack.push(node.left)33 }34 }35 return result36}37/**38 * @description 深度ä¼å
æç´¢,éå½çæ¬39 */40const dfsr = (root: NumberTree) => {41 const result: number[] = []42 const dfs = (node: NumberTree) => {43 if (node) {44 result.push(node.value)45 dfs(node.left)46 dfs(node.right)47 }48 }49 dfs(root)50 return result51}...
search.js
Source:search.js
1const util = require("util");2const tree = require("./tree");3// Linear Search4let beasts = ["Centaur", "Godzilla", "Mosura", "Minotaur", "Hydra", "Nessie"];5// console.log(beasts.indexOf("Godzilla"));6// console.log(beasts.findIndex((beast) => beast === "Godzilla"));7// console.log(beasts.find((beast) => beast === "Godzilla"));8// console.log(beasts.includes("Godzilla"));9// Binary Search10// Breath Fist Search (BFS)11const numberTree = new tree.BinarySearchTree();12numberTree.insert(9);13numberTree.insert(4);14numberTree.insert(6);15numberTree.insert(20);16numberTree.insert(170);17numberTree.insert(15);18numberTree.insert(1);19console.log(20 util.inspect(JSON.parse(JSON.stringify(numberTree)), false, null, true)...
Using AI Code Generation
1var NumberTree = require('wptree').NumberTree;2var tree = new NumberTree();3tree.add(5);4tree.add(3);5tree.add(7);6tree.add(1);7tree.add(4);8tree.add(6);9tree.add(8);10console.log(tree);11console.log(tree.inorder());12console.log(tree.preorder());13console.log(tree.postorder());14var StringTree = require('wptree').StringTree;15var tree = new StringTree();16tree.add('apple');17tree.add('banana');18tree.add('grape');19tree.add('mango');20tree.add('orange');21tree.add('pear');22tree.add('peach');23console.log(tree);24console.log(tree.inorder());25console.log(tree.preorder());26console.log(tree.postorder());27var ObjectTree = require('wptree').ObjectTree;28var tree = new ObjectTree();29tree.add({name: 'apple', type: 'fruit'});30tree.add({name: 'banana', type: 'fruit'});31tree.add({name: 'grape', type: 'fruit'});32tree.add({name: 'mango', type: 'fruit'});33tree.add({name: 'orange', type: 'fruit'});34tree.add({name: 'pear', type: 'fruit'});35tree.add({name: 'peach', type: 'fruit'});36console.log(tree);37console.log(tree.inorder());38console.log(tree.preorder());39console.log(tree.postorder());40var CustomTree = require('wptree').CustomTree;41var tree = new CustomTree(function (a, b) {42 return a.name < b.name;43});44tree.add({name: 'apple', type: 'fruit'});45tree.add({name: 'banana', type: 'fruit'});46tree.add({name: 'grape', type: 'fruit'});47tree.add({name: 'mango', type: 'fruit'});48tree.add({name: 'orange', type: 'fruit'});49tree.add({name: 'pear', type: 'fruit'});50tree.add({name: 'peach', type: 'fruit'});51console.log(tree);52console.log(tree.inorder());53console.log(tree.preorder());54console.log(tree.postorder());
Using AI Code Generation
1var NumberTree = require("wptree").NumberTree;2var tree = new NumberTree();3tree.insert(1);4tree.insert(2);5tree.insert(3);6tree.insert(4);7tree.insert(5);8tree.insert(6);9tree.insert(7);10tree.insert(8);11tree.insert(9);12tree.insert(10);13tree.insert(11);14tree.insert(12);15tree.insert(13);16tree.insert(14);17tree.insert(15);18tree.insert(16);19tree.insert(17);20tree.insert(18);21tree.insert(19);22tree.insert(20);23tree.insert(21);24tree.insert(22);25tree.insert(23);26tree.insert(24);27tree.insert(25);28tree.insert(26);29tree.insert(27);30tree.insert(28);31tree.insert(29);32tree.insert(30);33tree.insert(31);34tree.insert(32);35tree.insert(33);36tree.insert(34);37tree.insert(35);38tree.insert(36);39tree.insert(37);40tree.insert(38);41tree.insert(39);42tree.insert(40);43tree.insert(41);44tree.insert(42);45tree.insert(43);46tree.insert(44);47tree.insert(45);48tree.insert(46);49tree.insert(47);50tree.insert(48);51tree.insert(49);52tree.insert(50);53tree.insert(51);54tree.insert(52);55tree.insert(53);56tree.insert(54);57tree.insert(55);58tree.insert(56);59tree.insert(57);60tree.insert(58);61tree.insert(59);62tree.insert(60);63tree.insert(61);64tree.insert(62);65tree.insert(63);66tree.insert(64);67tree.insert(65);68tree.insert(66);69tree.insert(67);70tree.insert(68);71tree.insert(69);72tree.insert(70);73tree.insert(71);74tree.insert(72);75tree.insert(73);76tree.insert(74);77tree.insert(75);78tree.insert(76);79tree.insert(77);80tree.insert(78);81tree.insert(79);82tree.insert(80);83tree.insert(81);84tree.insert(82);85tree.insert(83);86tree.insert(84);87tree.insert(85);88tree.insert(86);89tree.insert(87);90tree.insert(88);91tree.insert(89);92tree.insert(90);93tree.insert(91);94tree.insert(92);95tree.insert(93);96tree.insert(94);97tree.insert(95);
Using AI Code Generation
1var tree = new NumberTree();2tree.insert(5);3tree.insert(3);4tree.insert(7);5tree.insert(2);6tree.insert(4);7tree.insert(6);8tree.insert(8);9tree.insert(1);10tree.insert(9);11tree.insert(0);12tree.insert(10);13tree.insert(11);14tree.insert(12);15tree.insert(13);16tree.insert(14);17tree.insert(15);18tree.insert(16);19tree.insert(17);20tree.insert(18);21tree.insert(19);22tree.insert(20);23tree.insert(21);24tree.insert(22);25tree.insert(23);26tree.insert(24);27tree.insert(25);28tree.insert(26);29tree.insert(27);30tree.insert(28);31tree.insert(29);32tree.insert(30);33tree.insert(31);34tree.insert(32);35tree.insert(33);36tree.insert(34);37tree.insert(35);38tree.insert(36);39tree.insert(37);40tree.insert(38);41tree.insert(39);42tree.insert(40);43tree.insert(41);44tree.insert(42);45tree.insert(43);46tree.insert(44);47tree.insert(45);48tree.insert(46);49tree.insert(47);50tree.insert(48);51tree.insert(49);52tree.insert(50);53tree.insert(51);54tree.insert(52);55tree.insert(53);56tree.insert(54);57tree.insert(55);58tree.insert(56);59tree.insert(57);60tree.insert(58);61tree.insert(59);62tree.insert(60);63tree.insert(61);64tree.insert(62);65tree.insert(63);66tree.insert(64);67tree.insert(65);68tree.insert(66);69tree.insert(67);70tree.insert(68);71tree.insert(69);72tree.insert(70);73tree.insert(71);74tree.insert(72);75tree.insert(73);76tree.insert(74);77tree.insert(75);78tree.insert(76);79tree.insert(77);80tree.insert(78);81tree.insert(79);82tree.insert(80);83tree.insert(81);84tree.insert(82);85tree.insert(83);86tree.insert(84);87tree.insert(85);88tree.insert(86);89tree.insert(87);90tree.insert(88);91tree.insert(89);92tree.insert(90);93tree.insert(91);94tree.insert(92);95tree.insert(93);96tree.insert(94);97tree.insert(95);98tree.insert(96);99tree.insert(97
Using AI Code Generation
1var wptree = require('wptree');2var tree = new wptree.NumberTree();3tree.add(5);4tree.add(3);5tree.add(6);6tree.add(1);7tree.add(4);8tree.add(7);9tree.add(2);10var wptree = require('wptree');11var tree = new wptree.StringTree();12tree.add('a');13tree.add('b');14tree.add('c');15tree.add('d');16tree.add('e');17tree.add('f');18tree.add('g');19var wptree = require('wptree');20var tree = new wptree.ObjectTree();21tree.add({name: 'a'});22tree.add({name: 'b'});23tree.add({name: 'c'});24tree.add({name: 'd'});25tree.add({name: 'e'});26tree.add({name: 'f'});27tree.add({name: 'g'});28var wptree = require('wptree');29var tree = new wptree.BinarySearchTree();30tree.add(5);31tree.add(3);32tree.add(6);33tree.add(1);34tree.add(4);35tree.add(7);36tree.add(2);
Using AI Code Generation
1var tree = new NumberTree();2tree.add(10);3tree.add(5);4tree.add(15);5tree.add(20);6tree.add(3);7tree.add(7);8tree.add(12);9tree.add(17);10tree.add(25);11tree.add(1);12tree.add(4);13tree.add(6);14tree.add(8);15tree.add(11);16tree.add(13);17tree.add(16);18tree.add(18);19tree.add(24);20tree.add(26);21var result = tree.find(11);22tree.remove(11);23var min = tree.min();24var max = tree.max();25var size = tree.size();26var height = tree.height();27var depth = tree.depth(17);28var value = tree.valueAtDepth(2);29var count = tree.countAtDepth(2);30var leaves = tree.leaves();31var single = tree.singleChildren();32var double = tree.doubleChildren();33var none = tree.noChildren();34var left = tree.leftChildren();35var right = tree.rightChildren();36var both = tree.bothChildren();37var leftOnly = tree.leftOnlyChildren();38var rightOnly = tree.rightOnlyChildren();39var both = tree.bothChildren();40var leftOnly = tree.leftOnlyChildren();41var rightOnly = tree.rightOnlyChildren();
Using AI Code Generation
1var wptree = require('./wptree.js');2var tree = new wptree.NumberTree();3tree.add(3);4tree.add(1);5tree.add(2);6tree.add(4);7console.log(tree.contains(3));8console.log(tree.contains(4));9console.log(tree.contains(5));10console.log(tree.contains(2));11console.log(tree.contains(1));12module.exports = {13 NumberTree: function() {14 function Node(value) {15 this.value = value;16 this.left = null;17 this.right = null;18 }19 this.root = null;20 this.add = function(value) {21 if (this.root == null) {22 this.root = new Node(value);23 } else {24 var current = this.root;25 while (true) {26 if (value < current.value) {27 if (current.left == null) {28 current.left = new Node(value);29 break;30 } else {31 current = current.left;32 }33 } else if (value > current.value) {34 if (current.right == null) {35 current.right = new Node(value);36 break;37 } else {38 current = current.right;39 }40 } else {41 break;42 }43 }44 }45 }46 this.contains = function(value) {47 var current = this.root;48 while (current) {49 if (value < current.value) {50 current = current.left;51 } else if (value > current.value) {52 current = current.right;53 } else {54 return true;55 }56 }57 return false;58 }59 }60}
Using AI Code Generation
1var wptree = require('./wptree.js');2var nt = new wptree.NumberTree();3nt.add(50);4nt.add(25);5nt.add(75);6nt.add(12);7nt.add(37);8nt.add(63);9nt.add(87);10nt.add(6);11nt.add(18);12nt.add(31);13nt.add(43);14nt.add(56);15nt.add(68);16nt.add(81);17nt.add(93);18nt.add(3);19nt.add(9);20nt.add(15);21nt.add(21);22nt.add(28);23nt.add(34);24nt.add(40);25nt.add(46);26nt.add(53);27nt.add(59);28nt.add(65);29nt.add(71);30nt.add(78);31nt.add(84);32nt.add(90);33nt.add(96);34nt.print();35nt.remove(50);36console.log('37');38nt.print();39nt.remove(12);40console.log('41');42nt.print();43nt.remove(43);44console.log('45');46nt.print();47nt.remove(87);48console.log('49');50nt.print();51nt.remove(25);52console.log('53');54nt.print();55nt.remove(75);56console.log('57');58nt.print();59nt.remove(3);60console.log('61');62nt.print();63nt.remove(9);64console.log('65');66nt.print();67nt.remove(21);68console.log('69');70nt.print();71nt.remove(28);72console.log('73');74nt.print();75nt.remove(34);76console.log('77');78nt.print();79nt.remove(40);80console.log('81');82nt.print();83nt.remove(46);84console.log('85');86nt.print();87nt.remove(53);88console.log('89');90nt.print();91nt.remove(59);92console.log('93');94nt.print();95nt.remove(65);96console.log('97');98nt.print();99nt.remove(71);100console.log('101');102nt.print();103nt.remove(78);104console.log('105');106nt.print();
Using AI Code Generation
1for(var i = 0; i < 100; i++){2 tree.insert(i);3}4tree.printTree();5var tree = new wptree.StringTree();6tree.insert("string");7tree.printTree();8var tree = new wptree.ObjectTree();9tree.insert({key:"value"});10tree.printTree();11var tree = new wptree.ArrayTree();12tree.insert([1,2,3]);13tree.printTree();14var tree = new wptree.MixedTree();15tree.insert([1,2,3]);16tree.insert({key:"value"});17tree.printTree();18var tree = new wptree.MixedTree();19tree.insert([1,2,3]);20tree.insert({key:"value"});21tree.printTree();22var tree = new wptree.MixedTree();23tree.insert([1,2,3]);24tree.insert({key:"value"});25tree.printTree();26var tree = new wptree.MixedTree();27tree.insert([1,2,3]);28tree.insert({key:"value"});29tree.printTree();30var tree = new wptree.MixedTree();31tree.insert([1,2,3]);32tree.insert({key:"value"});33tree.printTree();34var tree = new wptree.MixedTree();35tree.insert([1,2,3]);36tree.insert({key:"value"});37tree.printTree();38var tree = new wptree.MixedTree();39tree.insert([1,2,3]);40tree.insert({key:"value"});41tree.printTree();42var tree = new wptree.MixedTree();43tree.insert([1,2,3]);44tree.insert({key:"value"});45tree.printTree();46var tree = new wptree.MixedTree();47tree.insert([1,2,
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!