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
function Stack() { | |
this.dataStore = []; | |
this.top = 0; | |
this.clear = clear; | |
this.push = push; | |
this.pop = pop; | |
this.peek = peek; | |
this.length = length; | |
} |
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
// Factorial | |
function factorial(n) { | |
if(n === 0) { | |
return 1; | |
} else { | |
return n * factorial(n-1); | |
} | |
} | |
factorial(5) //= 120 |
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
function findBrackets(str){ | |
var brackets = "{}[]()"; | |
var result = []; | |
var position; | |
for (var i = 0, max = str.split('').length; i < max; i++) { | |
position = brackets.indexOf(str.split('')[i]); | |
if (position > -1) { | |
if (position % 2 === 0) { |
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
var a = [ | |
[1,2,3,5], | |
[1,5,9,5], | |
[1,5,0,8], | |
[9,5,0,5] | |
] | |
function diagonalsX() { | |
var result = 0; |
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
function Stack() { | |
this.dataStore = []; | |
this.top = 0; | |
this.clear = clear; | |
this.push = push; | |
this.pop = pop; | |
this.peek = peek; | |
this.length = length; | |
} |
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
function factorial(n) { | |
if(n === 0) { | |
return 1; | |
} else { | |
return n * factorial(n-1); | |
} | |
} |
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
# Exercises | |
Write a function that inserts an element into a list only if the element to be insertedis larger than any of the elements currently in the list. | |
Larger can mean either greaterthan when working with numeric values, or further down in the alphabet, whenworking with textual values. | |
function List () { | |
this.array = [2,36,"a","d"]; | |
this.add = add; | |
this.check = check; | |
this.print = print; |