Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

Conversation

@AraceliGS
Copy link

No description provided.

Copy link
Collaborator

@nicolethenerd nicolethenerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¡Bien hecho!
Tengo algunos comentarios de la organización de tu código. Estaba muy impresionado con su uso de la guía de estilo (https://github.com/Laboratoria/js-style-guide#agrega-espacios-a-cada-lado-de-los-operadores).

<title>Cifrado César</title>
</head>
<body>
<script type="text/javascript" src = "js/app.js"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

borra los espacios alrededor del =

// Creando función cipher

function cipher(str) {
var index1 = []; // [65, 66, 67] || [97, 98, 99]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No es obvio en tu código porque los números 65 y 97 son importantes. Puedes usar constantes, como

var UPPERCASE_A = 65;
var LOWERCASE_A = 97;

Y en otras partes de tu código, como la línea 12, puedes usar UPPERCASE_A en lugar de 65.

var index1 = []; // [65, 66, 67] || [97, 98, 99]
var indexAscii = []; // [72, 73, 74] || [104, 105, 106]
var letters1 = []; // ['H', 'I', 'J'] || ['h', 'i', 'j']
if (str === str.toUpperCase()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu código no funciona si str contiene una combinación de letras mayúsculas y minúsculas (por ejemplo, probar el input 'Hola')

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Es mejor poner el if dentro del for loop, y probar cada letra para ver si es mayúsculas o minúsculas - no probes el string completo

var indexAscii = []; // [72, 73, 74] || [104, 105, 106]
var letters1 = []; // ['H', 'I', 'J'] || ['h', 'i', 'j']
if (str === str.toUpperCase()) {
for (var i = 0; i < str.length; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este loop y la variable index1 no son necesarios. Puedes usar str.charCodeAt(j) en la línea 12.

for (var i = 0; i < str.length; i++) {
index1.push(str.charCodeAt(i));
}
for (var j = 0; j < index1.length; j++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puedes repetir la variable indice de un loop - puedes usar 'i' en todos tus loops, excepto cuando hay un loop dentro de otro loop.

}
}

if (str === str.toLowerCase()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Las líneas 21-37 no son necesarios si mueves el if dentro del loop, como describí anteriormente.


// Creando función decipher

function decipher(str) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tengo comentarios similares para esta función:
El if en la línea 50 y las líneas 67-82 no son necesarios - es mejor probar si las letras son mayúsculas o minúsculas dentro del loop.

}

if (str === str.toLowerCase()) {
for (var num1 = 0; num1 < str.length; num1++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esta loop no es necesario - puedes usar str.charCodeAt en el loop segundo.

}


for (var num3 = 0; num3 < indexAscii.length; num3++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

También este loop puede ser combinado con el segundo loop - no necesitas el arreglo indexAscii - puedes hacer el string nuevo directamente.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants