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
// returns an array containing all permutations of a given string | |
const permute = str => { | |
let permutations = []; | |
if ( str.length <= 1 ) { | |
return [str]; | |
} | |
for ( let i = 0; i < str.length; i++ ) { | |
let char = str[i]; |
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 isBalanced = str => { | |
const arr = str.split(''); | |
const res = arr.reduce((acc, item) => { | |
if ( acc.slice(-1)[0] === '(' ) { | |
if ( item === ')' ) { | |
acc.pop(); | |
return acc; | |
} | |
} | |
if ( item === '(' || item === ')' ) { |
NewerOlder