From 07700ae251548c4206e2fdf3dd46bb6cb0c0d9b4 Mon Sep 17 00:00:00 2001 From: billalp Date: Mon, 28 Oct 2019 11:03:08 +0000 Subject: [PATCH] Letters work as an array --- caesar/caesar.js | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/caesar/caesar.js b/caesar/caesar.js index f667b85..91b417a 100644 --- a/caesar/caesar.js +++ b/caesar/caesar.js @@ -1,24 +1,35 @@ const caesar = function(value, addBy) { + const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split(''); - const newVal = value.toString().toLowerCase(); + const valueLowerCase = value.toLowerCase(); + const valueArray = valueLowerCase.split(''); - if (alphabet.includes(newVal) === true) { - var letterIndex = alphabet.indexOf(newVal); - var finalIndex = letterIndex + addBy; + var newArr = []; - return alphabet[finalIndex].toUpperCase(); - } else { - return 'Value is not a part of the alphabet'; + for (var i = 0; i < valueArray.length; i++) { + if (alphabet.includes(valueArray[i])) { + let letterIndex = alphabet.indexOf(valueArray[i]); + let finalIndex = letterIndex + addBy; + + newArr.push(alphabet[finalIndex]); + } else { + // return 'is not a part of the alphabet'; + return 'no'; + } } + return newArr.join(''); } module.exports = caesar; /* Pseudocode - - - - +1 Take input and place in an array - then we have an array of letters +2 If not a letter then ignore +3 If a space or ! then return space or ! +4 If it is a letter, it comes to the end then keep going around +5 +6 +7 Factor in minus */