This file contains hidden or 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
// Throttle | |
// Debounce | |
// Currying | |
// Composition | |
// Bind | |
// Object.assign | |
// ConfromTo |
This file contains hidden or 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 Node { | |
constructor (val) { | |
this.val = val | |
this.children = [] | |
} | |
addChildren (val) { | |
const node = new Node(val) | |
this.children.push(node) | |
return node |
This file contains hidden or 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 cacheData = { | |
'url1' : {a: 3} | |
} | |
// not completely async | |
function ajax (url, fn) { | |
if (cacheData[url]) { | |
fn(cacheData[url]) | |
return |
This file contains hidden or 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 isPrime (no) { | |
if (no === 1 || no === 0) { | |
return false | |
} | |
for(var start = 2; start <= Math.sqrt(no) ; start ++) { | |
if (no % start === 0) { | |
return false | |
} | |
} |
This file contains hidden or 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 Set() { | |
// the var collection will hold the set | |
var collection = []; | |
// this method will check for the presence of an element and return true or false | |
this.has = function(element) { | |
return (collection.indexOf(element) !== -1); | |
}; | |
// this method will return all the values in the set | |
this.values = function() { | |
return collection; |
This file contains hidden or 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 arr = [] | |
for(var start = 0; start < 9675; start++) { | |
arr.push(start) | |
} | |
function convertArrToObject (arr, groupSize=100) { | |
var count = Math.floor(arr.length / groupSize) + 1 |
This file contains hidden or 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 arr = []; | |
for(var i=100000;i>=1;i--) { | |
arr.push(i); | |
} | |
for(var i=1;i<=100000;i++) { | |
arr.push(i); | |
} |
This file contains hidden or 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 Counter { | |
constructor() { | |
this.counter = 2 | |
this.info = {name: 'abhinav', age: 29} | |
} | |
add () { | |
this.counter += 1 | |
} | |
This file contains hidden or 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 arr = [1,2,[1,2, [3,4]]] | |
const flattenMap = (arr) => { | |
let returnArr = [] | |
for(var start =0; start <= arr.length-1;start++) { | |
returnArr = Array.isArray(arr[start]) ? returnArr.concat(flattenMap(arr[start])) : returnArr.concat(arr[start]) | |
} | |
return returnArr | |
} |
This file contains hidden or 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 treeTraversal (arr, i) { | |
if (!arr[i]) { | |
return | |
} | |
treeTraversal(arr, 2*i+1) | |
console.log(arr[i]) | |
treeTraversal(arr, 2*i+2) | |
} |