Skip to content

Instantly share code, notes, and snippets.

View kavitshah8's full-sized avatar

Kavit Shah kavitshah8

  • Adobe
  • Bay Area, CA
View GitHub Profile
@kavitshah8
kavitshah8 / exerceise-2.js
Last active September 28, 2015 15:53
scope and this
name = 'Kavit';
var team = {
name: 'Kevin',
member: {
name: 'Nik',
getName: function () {
return this.name;
}
}
class LinkedList {
constructor() {
this.head = null;
}
insertNodeAtTail(val) {
var node = {
data: val,
@kavitshah8
kavitshah8 / hanoi.js
Last active January 11, 2016 15:46
Stack
'use strict';
function stepsToSolveHanoiT(height, srcP, desP, bufferP) {
if (height >= 1) {
// Move a tower of height-1 to the buffer peg, using the destination peg.
stepsToSolveHanoiT(height - 1, srcP, bufferP, desP);
// Move the remaining disk to the destination peg.
@kavitshah8
kavitshah8 / queue.js
Last active October 11, 2015 21:22
Queue
function Queue () {
this.first = null;
this.last = null;
}
Queue.prototype.enqueue = function (val) {
var q1 = {
data : val,
next : null
'use strict';
function BinarySearchTree() {
this.root = null;
}
BinarySearchTree.prototype.insertNode = function (val) {
var node = {
data : val,
@kavitshah8
kavitshah8 / half-pyramid-2.js
Last active November 28, 2018 13:21
Pyramid Patterns
"use strict";
function createHalfPyramid (height) {
for (var i = 1; i <= height; i++) {
var row = '';
for (var j = 1; j <= (height - i); j++) {
row += ' ';
}
@kavitshah8
kavitshah8 / array-compression.js
Last active January 21, 2016 06:02
Company Specific
'use strict';
function compressArr (arr) {
var start = arr[0];
var stop = start;
var arrLength = arr.length;
var result = '';
for (var i = 1; i < arrLength; i++) {
@kavitshah8
kavitshah8 / short-circuit-operator.js
Last active December 13, 2015 03:28
Logical operators
'use strict'
function f1 () {
console.log('f1 called');
return false;
}
function f2 () {
console.log('f2 called');
@kavitshah8
kavitshah8 / debounce.js
Last active March 14, 2017 05:53
Debounce
// Returns a function, that, as long as it continues to be invoked, will not be triggered.
// The function will be called after it stops being called for N milliseconds.
function debounce (cb, wait) {
var timeoutID
return function () {
clearTimeout(timeoutID)
timeoutID = setTimeout(cb, wait)
}
'use strict';
var express = require('express');
var compression = require('compression');
var app = express();
var oneYear;
// gzip the static resources before seding to browser, if the browser supports gzip compression