This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //palíndromo [3,2,5,2,3] == True palindromo [3,2,5,6,2,3] == False | |
| var element0 = [3, 2, 5, 2, 3]; | |
| var element1 = ["x", "s"]; | |
| var element2 = [3, 2, 5, 6, 2, 3]; | |
| //forma funcional | |
| var palindromof = x => { | |
| x = x + ""; | |
| var invertir = x.split("").reverse().join(""); | |
| //comparación | |
| return x == invertir; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //string “Laboratoria Rocks” | |
| var element = "Laboratoria Rocks"; | |
| //forma clásica | |
| var invertir = x => { | |
| x = x + ""; | |
| return x.split("").reverse().join(""); | |
| } | |
| // forma funcional | |
| // https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Array/reduceRight | |
| var invertirf = element.split("").reduceRight((x, y) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //forma funcional | |
| var element = [ | |
| { | |
| name: 'Rangi', | |
| mail: 'rangibecerra@gmail.com', | |
| date: '26-01-1985'}, | |
| { | |
| name: 'Mohana', | |
| mail: 'moharan28@hotmail.com', | |
| date:'27-02-1895'}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //invertir un número | |
| var invertir = x => { | |
| if (x === "") { | |
| return ""; | |
| } | |
| else { | |
| //console.log(x); | |
| return invertir(x.substr(1)) + x.charAt(0); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //si un número es positivo | |
| var positivo = x => { | |
| if(x>0) { | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| } | |
| console.log(positivo(5)); | |
| console.log(positivo(-2)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //forma funcional | |
| var alumnos = [ | |
| { | |
| nombre: 'Pedro', | |
| notas: [4, 4, 4] | |
| }, { | |
| nombre: 'Juan', | |
| notas: [7, 7, 7, 7] | |
| }, { | |
| nombre: 'Diego', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function (){ | |
| var loop = []; | |
| for (var i = 1; i <= 100; i++) { | |
| loop.push(i); | |
| if (i % 3 === 0 && i % 5 === 0) { | |
| loop.push("beetrack"); | |
| } | |
| else if (i % 3 === 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var add = (a,b) => { | |
| var sum = function (b){ | |
| return a+b; | |
| }; | |
| if(typeof b == "undefined"){ | |
| return sum; | |
| }else{ | |
| return sum(b); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var duplicate = (array) => { | |
| return array + "," + array; | |
| } | |
| console.log(duplicate([4,3,2,1,0])); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function printPrimes() { | |
| // Ahora debemos iterar desde `2` hasta `i / 2` usando una variable `j` como | |
| // contador. | |
| for (var i = 2; i < 20; i++) { | |
| var isPrime = true; | |
| for (var j = 2; j <= i/2; j++){ | |
| // Para cada `j` comprueba si la división `i / j` deja un residuo. | |
| if (i % j === 0) { | |
| isPrime = false; | |
| } |