Created
May 22, 2018 18:25
-
-
Save JordanAdams/8632b8812453cfbb1e6f5bc332688bf4 to your computer and use it in GitHub Desktop.
CodeUp - Karen (22nd May 2018)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mapping between letters and values | |
const numbers = { | |
A: 1, | |
B: 2, | |
C: 3, | |
D: 4, | |
E: 5, | |
F: 6, | |
G: 7 | |
// ... | |
}; | |
// create a counter | |
let counter = 0; | |
// get input | |
const input = process.argv[2].toUpperCase(); // ==> HELLO | |
// get letters | |
const letters = input.split(''); // => ['H', 'E', 'L', 'L', 'O'] | |
// loop over the letters | |
for (const letter of letters) { | |
// get the value of the letter or fallback to zero | |
const number = numbers[letter] || 0; | |
// increment a counter with the number of the letter | |
counter += number; | |
} | |
// output the counter | |
console.log(counter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment