DEV Community

loading...

Discussion on: Daily Challenge #254 - The Vowel Code

Collapse
thomasledoux1 profile image
Thomas Ledoux • Edited

My Javascript solution:

var vowels = ['a', 'e', 'i', 'o', 'u'];

function encode(input) {
  return [...input].map(char => vowels.includes(char) ? vowels.indexOf(char)+1 : char).join('');
}

function decode(input) {
  return [...input].map(char => Number(char) ? vowels[Number(char)-1] : char).join('');
}