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
| /********************************************************************* | |
| Solución funcional | |
| La más elegante, y ahora todos sabemos ;) | |
| *********************************************************************/ | |
| function crearSaludos1(array) { | |
| return array.map(function(nombre){ |
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 crearSaludo(array) { | |
| var resultado = []; | |
| for (var j=0, len = array.length; j<len; j++) { | |
| var nombre = array[j]; | |
| resultado.push(function(){ | |
| console.log("Hola " + nombre); | |
| }); | |
| } | |
| return resultado; | |
| } |
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
| //Imperative | |
| var checkAccessor1 = function(accesor) { | |
| var steps = accesor.split('.'); | |
| var cursor = steps[0]; | |
| var acumulator = cursor; | |
| for (var j=1, len = steps.length;j<len;j++) { | |
| cursor += '.' + steps[j]; | |
| acumulator += ' && ' + cursor; | |
| } |
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.prototype.memorizaParametro = function(parametro) { | |
| var funcionSobreLaQueSeEjecuto_memorizaParametro = this; | |
| return function() { | |
| var argsArray = Array.prototype.slice.call(arguments,0);//Convertimos en array | |
| argsArray.unshift(parametro); | |
| return funcionSobreLaQueSeEjecuto_memorizaParametro.apply(this,argsArray); | |
| } | |
| } | |
| //Primer ejemplo: uso puramente funcional |
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.prototype.memorizaParametro = function(parametro) { | |
| var funcionSobreLaQueSeEjecuto_memorizaParametro = this; | |
| return function() { | |
| var argsArray = Array.prototype.slice.call(arguments,1); //Menos el primero | |
| argsArray.unshift(parametro); | |
| return funcionSobreLaQueSeEjecuto_memorizaParametro.apply(this,argsArray); | |
| } | |
| } | |
| //Primer ejemplo: uso puramente funcional |
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
| /* | |
| * El siguiente patrón | |
| * | |
| * function foo(param) { | |
| * param = param || valor_por_defecto | |
| * ... | |
| * | |
| * no representa ningún riesgo de cara al rendimiento. | |
| * | |
| * Con ECMAScript 5 tenemos la posibilidad |
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
| // FUNCIONES AUXILIARES | |
| /* | |
| * La siguiente función cuenta las propiedades | |
| * (tanto propias como hereradas) de un objeto | |
| */ | |
| function contarPropiedades(obj) { | |
| var recuento = 0; | |
| for (propiedad in obj) recuento ++; |
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
| document.documentElement.childNodes[0].innerHTML = ''; | |
| var pres = document.getElementsByTagName('PRE'); | |
| for(var j = 0, len = pres.length; j<len;j++) { | |
| var sty= pres[j].style; | |
| sty.border='1px solid black'; | |
| sty.padding='8px'; | |
| sty.marginLeft='32px'; | |
| } | |
| var df = document.createDocumentFragment(); |
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
| -- Estrategias para aplanar arboles | |
| -- ATENCIÓN: Estas nuevas funciones no han sido probadas | |
| -- (No tengo GHC disponible en esta maquina) | |
| module Aplaneitor where | |
| data Tree a = Leaf a | Trees [Tree a] deriving(Show) | |
| cow = Trees [Leaf 1, Trees [ Leaf 2, Leaf 3], Leaf 4] | |
| -- Estrategias para aplanar arboles |
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 esArray(array) { | |
| return Object.prototype.toString.call(array) == '[object Array]'); | |
| } | |
| function desempaqueta(array,index) { | |
| Array.prototype.splice.apply(array, [index, 1].concat(array[index])); | |
| } | |
| function flatten(arr) { | |
| arr = arr.concat(); |