-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecipher-this.js
More file actions
28 lines (20 loc) · 785 Bytes
/
Copy pathDecipher-this.js
File metadata and controls
28 lines (20 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//Decipher this!
function decipherThis(str) {
let splitStr = str.split(' ')
let message = []
for (let i = 0; i < splitStr.length; i++) {
let word = splitStr[i]
//get word with number removed
let noNum = word.replace(/[0-9]/g, '')
//switch second and last letter after number removed
let switchLetter = noNum.length > 1 ? noNum[noNum.length - 1] + noNum.substring(1, noNum.length - 1) + noNum[0] : noNum
//get numbers from word
let matches = word.match(/(\d+)/g);
//turn numbers into charcter
let letter = String.fromCharCode(matches)
message.push(letter + switchLetter)
}
return message.join(' ')
};
console.log(
decipherThis('72eva 97 103o 97t 116sih 97dn 115ee 104wo 121uo 100o'), 'Have a go at this and see how you do');