Created
April 10, 2013 02:28
-
-
Save renzocastro/5351270 to your computer and use it in GitHub Desktop.
JavaScript: Soluciones del ejercicio con funciones
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
/* Ejercicios */ | |
// gist.github.com/5351166 | |
/* SOLUCIONES */ | |
// 1. | |
// Forma PRO | |
function reverso(texto){ | |
return texto.split('').reverse().join(''); | |
} | |
console.log( reverso('Area51') ); // 15aerA | |
// Forma normal | |
function reverso(texto){ | |
var res = ''; | |
var i; | |
var total = texto.length; | |
for(i=0;i<total;i++){ | |
res = texto.charAt(i) + res; | |
} | |
return res; | |
} | |
console.log( reverso('Area51') ); // 15aerA | |
// 2. | |
var frutas = "Manzana Platano Pera"; | |
console.log( frutas.split(" ") ); // ["Manzana", "Platano", "Pera"] | |
console.log( frutas.split("Pera") ); // ["Manzana Platano ", ""] | |
console.log( frutas.split("Platano") ); // ["Manzana ", " Pera"] | |
var array_frutas = frutas.split('Platano'); | |
console.log( array_frutas.join('') ); // "Manzana Pera" | |
console.log( array_frutas.join('Durazno') ); // "Manzana Durazno Pera" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment