Todorov_Stanimir

10. Letters Change Numbers

Jul 11th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. lettersChangeNumbers = (input) => {
  2.     console.log(input
  3.         .split(' ')
  4.         .filter(word => word.length)
  5.         .map(word => {
  6.             let number = Number(word.substring(1, word.length - 1));
  7.  
  8.             ('A' <= word.substring(0, 1) && word.substring(0, 1) <= 'Z')
  9.                 ? number = number / (word.substring(0, 1).charCodeAt() - 64)
  10.                 : number = number * ((word.substring(0, 1).charCodeAt() - 96));
  11.                
  12.             ('a' <= word.substring(word.length - 1) && word.substring(word.length - 1) <= 'z')
  13.                 ? number += (word.substring(word.length - 1).charCodeAt() - 96)
  14.                 : number -= (word.substring(word.length - 1).charCodeAt() - 64);
  15.  
  16.             return number
  17.         })
  18.         .reduce((a, b) => (a + b), 0)
  19.         .toFixed(2))
  20. }
Advertisement
Add Comment
Please, Sign In to add comment