Skip to content

Instantly share code, notes, and snippets.

@tobiasdalhof
Created January 6, 2018 23:42
Show Gist options
  • Save tobiasdalhof/00d7a302229855d1715520ac48a5bf1a to your computer and use it in GitHub Desktop.
Save tobiasdalhof/00d7a302229855d1715520ac48a5bf1a to your computer and use it in GitHub Desktop.
function alphabetPosition(text) {
const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('')
const letters = text.replace(/\s/g, '').split('');
const numbers = [];
letters.forEach(letter => {
letter = letter.toLowerCase();
alphabet.find((value, index) => {
if (value === letter) {
numbers.push(index + 1)
}
});
})
return numbers.join(' ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment