Skip to content

Instantly share code, notes, and snippets.

View sharmaabhinav's full-sized avatar
😀
Working

ABHINAV SHARMA sharmaabhinav

😀
Working
  • Bangalore
View GitHub Profile
// Throttle
// Debounce
// Currying
// Composition
// Bind
// Object.assign
// ConfromTo
class Node {
constructor (val) {
this.val = val
this.children = []
}
addChildren (val) {
const node = new Node(val)
this.children.push(node)
return node
var cacheData = {
'url1' : {a: 3}
}
// not completely async
function ajax (url, fn) {
if (cacheData[url]) {
fn(cacheData[url])
return
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
}
}
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;
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
var arr = [];
for(var i=100000;i>=1;i--) {
arr.push(i);
}
for(var i=1;i<=100000;i++) {
arr.push(i);
}
class Counter {
constructor() {
this.counter = 2
this.info = {name: 'abhinav', age: 29}
}
add () {
this.counter += 1
}
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
}
function treeTraversal (arr, i) {
if (!arr[i]) {
return
}
treeTraversal(arr, 2*i+1)
console.log(arr[i])
treeTraversal(arr, 2*i+2)
}