Guest User

Untitled

a guest
Jun 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. const letters = [
  2. 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  3. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
  4. ];
  5.  
  6. function alphabetPosition(text) {
  7. return text
  8. .split('')
  9. .map(item => letters.findIndex(e => e.toLowerCase() === item.toLowerCase()) + 1 || '')
  10. .filter(e => e)
  11. .map((item, i, text) => {
  12. if (text.length === 1 || i === 0) {
  13. return item;
  14. }
  15. return ' ' + item;
  16. })
  17. .toString()
  18. .replace(/,/g, '');
  19. }
Add Comment
Please, Sign In to add comment