Merge pull request #2 from BillalPatel/caeser

Caeser
This commit is contained in:
Billal Patel 2019-10-28 11:56:53 +00:00 committed by GitHub
commit 603d6a535a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 11 deletions

View File

@ -1,24 +1,39 @@
const caesar = function(value, addBy) {
const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
const newVal = value.toString().toLowerCase();
const specialChars = [' ', '!', ','];
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 if (specialChars.includes(valueArray[i])) {
newArr.push(valueArray[i]);
} else {
// return 'is not a part of the alphabet';
return 'Hello'
}
}
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 - DONE
3 If a space or ! then return space or ! - DONE
4 If it is a letter, it comes to the end then keep going around
5
6
7 Factor in minus
*/