Skip to content

Instantly share code, notes, and snippets.

@austinlyons
Last active January 6, 2017 21:01
Show Gist options
  • Save austinlyons/a1c3bcb7bb9b35fc6e82bf6146fe8f8d to your computer and use it in GitHub Desktop.
Save austinlyons/a1c3bcb7bb9b35fc6e82bf6146fe8f8d to your computer and use it in GitHub Desktop.
functional style JS
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