SHARE
TWEET

Untitled

a guest Jan 18th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution(name){
  2.    let answer = -1;
  3.    let idx = 0;
  4.    const newArr = [];
  5.    if(/[A]+/.test(name)) {
  6.        const match = name.match(/[A]+/g);
  7.        let max = 0;
  8.  
  9.        for(let i = 0; i < match.length; i++) {
  10.            if(match[i].length > max) {
  11.                max = match[i].length;
  12.                if(name.indexOf(match[i]) - 2 < max){
  13.                    idx = name.indexOf(match[i]);
  14.                }
  15.            }
  16.        }
  17.  
  18.  
  19.    } else idx = name.length - 1;
  20.  
  21.    for(let i = 0; i < idx; i++) {
  22.        newArr.push(name[i]);
  23.    }
  24.  
  25.    for(let j = name.length - 1; j >= idx; j--) {
  26.        newArr.push(name[j]);
  27.    }
  28.  
  29.    for(let k = 0; k < newArr.length; k++) {
  30.        if(newArr[k] !== “A”) {
  31.            const strNum = newArr[k].charCodeAt() - 65;
  32.            strNum > 13 ? answer += (26 - strNum) : answer += strNum;
  33.            answer += 1;
  34.        } else {
  35.            if(newArr[k+1] !== “A” && newArr[k+1]) {
  36.                answer += 1;
  37.            }
  38.        }
  39.    }
  40.  
  41.    return answer;
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top