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 Queue(){ | |
var storage = {}, | |
head = 0, | |
tail= 0; | |
return { | |
enQueue: function(item){ | |
storage[tail] = item; | |
tail++; | |
}, |
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(){ | |
var stack = {}; | |
var stackSize = 0; | |
return { | |
push: function(item){ | |
stack[stackSize] = item; | |
stackSize++; | |
}, | |
pop: function(){ |
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 deepEqual(a, b){ | |
if (typeof a === 'object' && a !== null && typeof b === 'object' && b !== null){ | |
var isEqual = Object.keys(a).length === Object.keys(b).length; | |
if (isEqual){ | |
for (var key in a){ | |
isEqual &= b.hasOwnProperty(key); | |
if (isEqual){ | |
isEqual &= deepEqual(a[key], b[key]); |
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
//Input: Array of Arrays of Cells | |
var grid = [['name', 'height', 'country'], | |
['Kilimanjaro',5895, 'Tanzania'], | |
['Everest',8848,'Nepal'], | |
['Mount Fuji',3776,'Japan'], | |
['Mont Blanc',4808,'Italy/France'], | |
['Vaalserberg',323,'Netherlands'], | |
['Denali', 6168,'United States'], | |
['Popocatepetl', 5465,'Mexico']]; |
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 Node(value) { | |
this.value = value; | |
this.next = undefined; | |
} | |
function SLinkedList() { | |
var head = undefined; | |
var length = 0; | |
return { |
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 Node(value) { | |
this.value = value; | |
this.next = undefined; | |
this.prev = undefined; | |
} | |
function DLinkedList() { | |
var head = undefined; | |
var tail = undefined; | |
var length = 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 isPermutation(strA, strB){ | |
var isValid = true; | |
//First validity check | |
if (!strA || !strB || strA.length !== strB.length){ | |
return !isValid; | |
} | |
//Get the map of characters and their occurences in strA | |
var charsMap = getMap(strA); |
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 isPermutation(strA, strB){ | |
var isValid = true; | |
//First validity check | |
if (!strA || !strB || strA.length !== strB.length){ | |
return !isValid; | |
} | |
var sortedA = sort(strA), sortedB = sort(strB); | |
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 Emitter(){ | |
var events = new Map(); | |
return { | |
subscribe: function(event_name, callback){ | |
//If events has event_name, then get the event Subscription and push to it. | |
//Else create new event, subscription and add to events. | |
var isEventExisted = events.has(event_name), index = 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
//Given 2 identical DOM trees (but not equal) and one element of the first DOM tree, | |
//how would you find this element in the second DOM tree | |
//Questions to ask: | |
//1. Input: input node is inside DOM tree? Or need to check if it exists? | |
//2. Output node needs to be identical? Same tag? | |
//3. Are comments, texts considered as child nodes? - Yes, need to use childNodes, No, use children. | |
var sameLevelNodeIdenticalTrees = { | |
getIndexOf: function(nodeList, node){ | |
return Array.prototype.indexOf.call(nodeList, node); | |
}, |
OlderNewer