Añadiendo arreglos con EsLint#80
Añadiendo arreglos con EsLint#80Azur-Azabache wants to merge 3 commits intoLaboratoria-learning:masterfrom
Conversation
|
@developerVilchez eslint OK |
nicolethenerd
left a comment
There was a problem hiding this comment.
¡Gran comienzo! Tu código está bien organizado y es fácil de leer. Desfortunadamente, todavía no funciona para cifrar y decifrar strings.
Las funciones cipher y decipher debe devolver strings, por ejemplo:
cipher('HOLA'); // --> 'OVSH' decipher('OVSH'); // --> 'HOLA'
JS/app.js
Outdated
| @@ -0,0 +1,28 @@ | |||
| var phrase = prompt('Ingresa la frase a decodificar'); | |||
| var newarray = []; | |||
There was a problem hiding this comment.
JS/app.js
Outdated
|
|
||
| function cipher(str) { | ||
| var array = phrase.split(''); | ||
| for (i = 0; i <= array.length - 1;i++) { |
There was a problem hiding this comment.
usa 'var' para declarar una nueva variable
for (var i = 0;
espacio antes de i++
for (i = 0; i <= array.length - 1; i++) {
JS/app.js
Outdated
| var newarray = []; | ||
| var unicode = []; | ||
|
|
||
| function cipher(str) { |
There was a problem hiding this comment.
No estás usando este parámetro 'str'
Debes reemplazar 'phrase' con 'str' dentro de esta función
JS/app.js
Outdated
|
|
||
| function cipher(str) { | ||
| var array = phrase.split(''); | ||
| for (i = 0; i <= array.length - 1;i++) { |
There was a problem hiding this comment.
Prefiero i < array.length a i <= array.length - 1
JS/app.js
Outdated
| @@ -0,0 +1,28 @@ | |||
| var phrase = prompt('Ingresa la frase a decodificar'); | |||
| var newarray = []; | |||
There was a problem hiding this comment.
Es importante que declares newarray dentro de la función cipher (por ejemplo, en la linea 6). De lo contrario, si ejecutas el código dos veces, el arreglo contendrá letras de ambas palabras.
JS/app.js
Outdated
| } | ||
| return newarray; | ||
| } | ||
| var arr = cipher(phrase); |
There was a problem hiding this comment.
La resulta de la función cipher debe ser un string - esta variable sería mejor llamada algo así como encodedPhrase.
JS/app.js
Outdated
| return newarray; | ||
| } | ||
| var arr = cipher(phrase); | ||
| function decipher(array2) { |
There was a problem hiding this comment.
El parámetro aquí debe ser string. decipher debe funcionar como así:
decipher('OVSH'); // --> 'HOLA'
JS/app.js
Outdated
| var arr2 = []; | ||
| for (i = 0; i <= array2.length - 1; i++) { | ||
| arr2.push(String.fromCharCode(array2[i])); | ||
| return arr2; |
There was a problem hiding this comment.
El return debe ser fuera del loop. Ahora, esta función devuelta el arreglo después del primer iteración del loop.
JS/app.js
Outdated
| } | ||
| if (isNaN(phrase) === false) { | ||
| 'Ingrese una frase por favor'; | ||
| } else { |
There was a problem hiding this comment.
No necesitas una else vacío.
JS/app.js
Outdated
| arr2.push(String.fromCharCode(array2[i])); | ||
| return arr2; | ||
| } | ||
| if (isNaN(phrase) === false) { |
There was a problem hiding this comment.
¿Qué está tratando de hacer aquí? Este código prueba si phrase es un número.
También, no necesitas === false - puedes usar un !, así :
if (!isNaN(phrase))
Pamela Rojas