Advertisement
EntropyStarRover

05. Equal Sums Left Right Position

Feb 21st, 2019
249
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sumOf(input){
  2.     let firstNum=Number(input.shift());
  3.     let secondNum=Number(input.shift());
  4.     let line="";
  5.    
  6.     for (let i=firstNum; i<=secondNum; i++){
  7.         let strNum=i+"";
  8.  
  9.         let leftSum=Number(strNum.charAt(0))+ Number(strNum.charAt(1));
  10.         let rightSum=Number(strNum.charAt(3))+ Number(strNum.charAt(4));
  11.    
  12.         if (leftSum<rightSum){
  13.             leftSum+=Number(strNum.charAt(2));
  14.         } else if (rightSum<leftSum){
  15.             rightSum+=Number(strNum.charAt(2));
  16.         }
  17.          if (leftSum==rightSum){
  18.             line+=i+ " ";
  19.         }
  20.        
  21.     }console.log(line);
  22.  
  23.   }
Advertisement
RAW Paste Data Copied
Advertisement