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 generate = function(numRows) { | |
var result = []; | |
for(var i = 1; i <= numRows; i++) { | |
var inner = []; | |
for(var j = 0; j < i; j++) { | |
inner.push(Math.abs(j + 1)); | |
} | |
if (j%2 > 0) { | |
for(var q = i - 1; q >= 1; q--) { | |
inner.push(Math.abs(q)); |
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 generate = function(numRows) { | |
var result = []; | |
for(var i = 1; i <= numRows; i++) { | |
var inner = []; | |
for(var j = 0; j < i; j++) { | |
inner.push(Math.abs(j + 1)); | |
} | |
for(var q = i - 1; q >= 1; q--) { | |
inner.push(Math.abs(q)); |
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 HashTable = function(limit=8) { | |
this._limit = limit; | |
this._storage = []; | |
this._count = 0; | |
} | |
//this._storage = [/*container*/[/*bucket*/], [[/*tuple*/], []]] |
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
HashTable.prototype.retrieve = function(key) { | |
var index = key.hashCode(); | |
var bucket = this._storage.get(index); | |
for (var i = 0; i < bucket.length; i++) { | |
if (bucket[i][0] === key) { | |
return bucket[i][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
class CashAmount { | |
constructor(amount) { | |
this.amount = amount; | |
} | |
} | |
CashAmount.prototype.totalInPennies = function() { | |
var pennies = this.amount * 100; | |
return pennies; | |
}; |
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 exponent = function(base, exp) { | |
if(exp === 0) { | |
return 1; | |
} | |
if(exp < 0) { | |
return 1/(base * exponent(base, -(exp+1))); | |
} | |
return base * exponent(base, exp-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
var factorial = function(n) { | |
if(n < 0) {return null}; | |
var result = 1; | |
if(n > 0) { | |
result = result * n * factorial(n - 1); | |
} return result; | |
}; |
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 isDivisible = function(n, c) { | |
if(n < 0) { | |
return isDivisible(-n, c); | |
} | |
if(n > 0 && n < c) { | |
return false; | |
} | |
if(n === 0) { | |
return true; | |
} |
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 flatten = function(items) { | |
var flat = []; | |
items.forEach(function(item) { | |
if (Array.isArray(item)) { | |
flat.push(...flatten(item)); | |
} else { | |
flat.push(item); | |
} | |
}); |
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
const hasPathToSum = function(node, targetSum) { | |
var total = 0; | |
var traverse = function(subnode) { | |
console.log('subnode: ', subnode); | |
if(!subnode.flag) { | |
console.log(total); | |
total += subnode.value; | |
} | |
if(subnode.children.length === 0 && total === targetSum) { | |
return true; |
OlderNewer