Last active
January 6, 2017 21:01
-
-
Save austinlyons/a1c3bcb7bb9b35fc6e82bf6146fe8f8d to your computer and use it in GitHub Desktop.
functional style JS
This file contains 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
let existing = "(((4 + 3) * 2) + 9)"; | |
const operators = ['*', '/', '+', '-']; | |
// find positions of operators in "existing" | |
let positions = existing | |
.split("") | |
.reduce((acc, character, idx) => { | |
if (operators.includes(character)) | |
acc.push(idx) | |
return acc; | |
}, []); | |
// outputs: [5, 10, 15] | |
console.log(positions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment