SHARE
TWEET

Problem05

a guest Jan 12th, 2016 114 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var test = '5-9+158/9*12596-1';
  2. var numbersArr = test.split(/[+,\-,*,\/]+/);
  3. var signsArr = test.split(/[0-9]*/);
  4. signsArr = signsArr.filter(function(e){return e});
  5. var theNewNumberArray = [];
  6. var newSignsArray = [];
  7.  
  8. for(var i = 0; i < signsArr.length; i++){
  9.     if(signsArr[i] !== '/' && signsArr[i] !== '*'){
  10.         theNewNumberArray.push(numbersArr[i + 1]);
  11.         newSignsArray.push(signsArr[i]);
  12.     }
  13.     if(signsArr[i] === '/'){
  14.         theNewNumberArray.push(numbersArr[i] / numbersArr[i + 1]);
  15.     }
  16.     if(signsArr[i] === '*'){
  17.         theNewNumberArray.push(numbersArr[i] * numbersArr[i + 1]);
  18.     }
  19. }
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