-
Notifications
You must be signed in to change notification settings - Fork 116
Añadiendo arreglos con EsLint #80
base: master
Are you sure you want to change the base?
Conversation
@developerVilchez eslint OK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
¡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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
¿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