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
//A basic doubly linked list structure | |
class Node { | |
constructor(val,prev = null, next = null){ | |
this.val = val; | |
this.prev = prev; | |
this.next = next; | |
} | |
} |
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
/** | |
* lazyLoader | |
* Check for elements in the document to be loaded later when visible to the user. | |
* @see https://developers.google.com/web/fundamentals/performance/lazy-loading-guidance/images-and-video/ | |
* @example | |
* <element src="" data-src="/url/" data-srcset="..." /> | |
*/ | |
(function (ready) { | |
if (document.readyState === "complete" || document.readyState === "interactive") { |
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
{ | |
let Singleton = (function(){ | |
let instance; | |
let createInstance = ()=>{ | |
let obj = {name: new Date()} | |
return obj; | |
} | |
return { | |
getInstance : () => { |
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
let setTimer = null | |
let debounce = (cb, delay) => { | |
clearTimeout(setTimer) | |
setTimer = setTimeout(cb, delay); | |
} |
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
export function throttle(callback, delay, options = {}) { | |
let flag = true | |
return () => { | |
if (flag) { | |
flag = false | |
setTimeout(() => { | |
callback(options) | |
flag = true | |
}, delay) | |
} |
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() { | |
this.length = 0; | |
} | |
Queue.prototype.push = function (item) { | |
var node = {item: item}; | |
if (this.last) { | |
this.last = this.last.next = node; | |
} else { | |
this.last = this.first = 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 GetValue1(){ | |
this.value = 10; | |
// using regular funciton to access the varialbe `this.value` | |
var printValue = function(){ | |
// Since printValue is an independent funciton and not a property of the GetValue1 constructor, | |
// so when this is called as constructor, printValue points to globalScopr | |
// where in case of reguar funciton call, this will bound to the execution context of GetValue1 | |
console.log('The value of this.value is, ', this.value) //consoles 20 | |
} | |
printValue() |