Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(str) {
  2.     let words = str.split(' ');
  3.     let final = 0;
  4.    
  5.     for(let item of words){
  6.         let first = item[0];
  7.         let last = item[item.length - 1];
  8.         let num = item.substring(1, item.length - 1);
  9.         let firstPos = 0;
  10.         let lastPos = 0;
  11.  
  12.        
  13.         if(first.charCodeAt(0) >= 97 && first.charCodeAt(0) <= 122){
  14.             firstPos = first.charCodeAt(0) - 96;
  15.             num = num * firstPos;
  16.         }else{
  17.             firstPos = first.charCodeAt(0) - 64;
  18.             num = num / firstPos;
  19.         }
  20.        
  21.         if(last.charCodeAt(0) >= 97 && last.charCodeAt(0) <= 122){
  22.             lastPos = last.charCodeAt(0) - 96;
  23.             num += lastPos;
  24.         }else{
  25.             lastPos = last.charCodeAt(0) - 64;
  26.             num -= lastPos;
  27.         }
  28.        
  29.         final += num;
  30.     }
  31.  
  32.     console.log(final.toFixed(2));
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement