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 findShort(s) { | |
var sSplit = s.split(' '); | |
var shortWord = s.length; | |
for(var i = 0; i < sSplit.length; i++){ | |
if(sSplit[i].length < shortWord){ | |
shortWord = sSplit[i].length; | |
} | |
} | |
return shortWord; | |
} |
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 disemvowel(str) { | |
return str.replace(/[aeiou]/ig,''); | |
} |
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
// We have an array of objects representing different people in our contacts lists. | |
// A lookUpProfile function that takes firstName and a property (prop) as arguments has been pre-written for you. | |
// The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact. | |
// If both are true, then return the "value" of that property. | |
// If firstName does not correspond to any contacts then return "No such contact" | |
// If prop does not correspond to any valid properties then return "No such property" | |
/* | |
//Setup | |
var contacts = [ |
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 palindrome(str) { | |
var strLowerCase = str.toLowerCase(); // Convierte cadena en minusculas. | |
var strClean = strLowerCase.replace(/[^\w\s]/gi, ''); // Limpia caracteres del texto. los reemplaza por vacio '' | |
var strSymbols = strClean.replace(/_/g, " "); // limpia el caracter "_" que por alguna razón no lo limpia la funcion anterior. | |
var strSpace = strSymbols.replace(/ /g, ''); // elimina los espacios en blanco. | |
var strReverse = strSpace.split('').reverse().join(''); // convierte el string en array lo reversa y lo une para formar una palabra. | |
if (strReverse !== strSpace) { // comprar el string reversado con el string limpio para ver si son iguales como un palindromor EJ: ojo === ojo | |
return false; // retorna falso si son diferentes, no son palindromos. | |
} else { |
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 findLongestWord(str) { | |
var strSplit = str.split(' '); // Se crea un array de la cadena str separado por espacio (' ') | |
var longestWord = 0; // Declara variable para almacenar el largo en numeros de la palabra mas larga encontrada | |
for (var i = 0; i < strSplit.length; i++) { // Se recorre el array de string | |
if (longestWord < strSplit[i].length) { // Compara si la cadena guardada es ms larga que la posicion del array. | |
longestWord = strSplit[i].length; // Guarda el tamaño de la cadena ms larga en la variable. | |
} | |
} | |
return longestWord; // Devuelve la variable con el largo del string :D. | |
} |
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 titleCase(str) { | |
str = str.toLowerCase().split(' '); // Convierto el string en minisculas y luego en array con la función split, y le doy el separador (' '). | |
for (var i = 0; i < str.length; i++) { // For para recorrer el array | |
str[i] = str[i].charAt(0).toUpperCase() + str[i].slice(1); // al indice del array convierto en mayuscula el primer caracter con la funcion charAt().toUpperCase() y despues con la funcion slice(1), extraigo el resto del texto y los sumo en una única cadena. | |
} | |
return str.join(' '); // Devuelvo la cadena unida separada por un espacio. | |
} | |
titleCase("I'm a little tea pot"); | |
/* str.length = 5 |
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 largestOfFour(arr) { | |
var finalArray = []; | |
for(i = 0; i < arr.length; i++) { // itera el array padre | |
var max = -Infinity; | |
for(j = 0; j < arr[i].length; j++) { // itera sobre cad sub array | |
if(arr[i][j] > max) { // compara cada elemento sucesivo del subarray con la variable max | |
max = arr[i][j]; // si es mayor entra el if y updatea max | |
} | |
} | |
finalArray.push(max); // empuja cada valor de max despues de los loops al array nuevo declarado vacio. |
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 confirmEnding(str, target) { | |
if (target === str.substr(str.length - target.length)) { // compara target con la cadena de texto, que la función substr le da como parametros de inicio y fin | |
return true; | |
} else { | |
return false; | |
} | |
} | |
confirmEnding("Open sesame", "same"); |
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 repeatStringNumTimes(str, num) { | |
if (num > 0) { // valida si el numero de repeticiones es un numero positivo | |
var repeatString = str.repeat(num); // funcion repeat con el parametro numero ingresado a la funcion | |
return console.log(repeatString); // retorma el string repetido | |
} else { | |
return console.log(""); // devuelve vacio si es un numero negativo, | |
} | |
} | |
repeatStringNumTimes("hola",2); // "holahola" |
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 truncateString(str, num) { | |
var dot = '.'; // asigna el punto a una variable String | |
var slice1 = str.slice(0, num) + dot.repeat(3); // primer valor a devolver variable recortada + los 3 puntos suman el limite de num | |
var slice2 = str.slice(0, (num - 3)) + dot.repeat(3); // segundo valor a devolver variable recortada + 3 puntos que no suman el limite de num | |
if (str.length > num && num <= 3) // si el largo de la variable es mayor al limite y el limire menor o igual a 2 | |
return console.log(slice1); // devuelve primera cadena que no considera los 3 puntos como suma del total de caracteres | |
else if (str.length > num && num > 3) // condicion opusta , si largo de string es mayor a limite y limite mayor a 3 | |
return console.log(slice2); // devuelve segunda cadena, que recorta el caracter por el limite y no se suman los 3 puntos como parte del string final | |
else |
OlderNewer