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
/* | |
A | |
/ \ | |
B C | |
/ \ / \ | |
D E F G | |
*/ |
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
// ** check for validate parenthesis | |
const isValidParenthesis = str => { | |
let brackets = 0; | |
for (let i = 0; i < str.length; i++) { | |
if (str.charAt(i) === "(") { | |
brackets++; | |
} else if (str.charAt(i) === ")") { | |
brackets--; | |
} else { |
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
Cons.fromArray = function(array) { | |
array = array.reverse(); | |
let last = new Cons(array.shift(), null); | |
array.forEach(function(item) { | |
last = new Cons(item, last); | |
}); | |
return last; | |
} |