Created
May 6, 2015 05:22
-
-
Save jamlfy/ee8edb99d8d9a7ab7e2d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const entra = "10+62*7*+"; | |
| function flaten (input, carch) { | |
| var a = 0, output = []; | |
| if(!carch) | |
| return input; | |
| var last = input[ input.length - 1 ]; | |
| var past = input[ input.length - 2 ]; | |
| if( (!last || !past ) && last != 0 && past != 0 ) | |
| return [ -1 ]; | |
| eval( 'a = ' + last + carch + past ); | |
| delete input[ input.length - 1 ]; | |
| delete input[ input.length - 2 ]; | |
| for (var i = input.length - 1; i >= 0; i--) | |
| if( input[i] ) output.push(input[i]); | |
| output.push(a); | |
| return output; | |
| } | |
| function solution(s) { | |
| var arr = []; | |
| for (var i = 0; i < s.length; i++) { | |
| var isNum = parseInt(s[i]); | |
| if(isNum || isNum === 0 ) arr.push(isNum); | |
| if(/\*|\-|\+|\/|\^/.test(s[i]) ) | |
| arr = flaten(arr, s[i]); | |
| console.log(arr); | |
| } | |
| return arr[0]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment