Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const letters = [
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
- 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
- ];
- function alphabetPosition(text) {
- return text
- .split('')
- .map(item => letters.findIndex(e => e.toLowerCase() === item.toLowerCase()) + 1 || '')
- .filter(e => e)
- .map((item, i, text) => {
- if (text.length === 1 || i === 0) {
- return item;
- }
- return ' ' + item;
- })
- .toString()
- .replace(/,/g, '');
- }
Add Comment
Please, Sign In to add comment