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; | |
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
//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); | |
}, |
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 FlattenArray(arr){ | |
var flattened = []; | |
while(arr.length){ | |
var element = arr.pop(); //start from end | |
//if (element instanceof Array) | |
//if (Object.prototype.toString.call(element) === '[object Array]') | |
if (Array.isArray(element)){ | |
arr = arr.concat(element); |
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 input: | |
// could be potentially more than 3 keys in the object above | |
// items = [ | |
// {color: 'red', type: 'tv', age: 18}, | |
// {color: 'silver', type: 'phone', age: 20} | |
// ... | |
// ] | |
// excludes = [ |
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
/* | |
If you were building a search tool and wanted search results to pop up as you | |
typed but the server call was taxing, write a function that gets called on every | |
key down but calls the server when the user stops typing for 400ms. | |
*/ | |
// <input type="text" class="js-search"> | |
/* | |
Questions to ask: | |
1. Each of input should have unique id, where is the id in this case? |
OlderNewer