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 / 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 / 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 += ' ';
}
'use strict';
function BinarySearchTree() {
this.root = null;
}
BinarySearchTree.prototype.insertNode = function (val) {
var node = {
data : val,
@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
@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.
class LinkedList {
constructor() {
this.head = null;
}
insertNodeAtTail(val) {
var node = {
data: val,
@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;
}
}
var cachedNumbers = {};
function calculateFibonacciSum (num) {
if(cachedNumbers[num]) {
return cachedNumbers[num];
}
if(('number' === typeof num) && num <= 0) {
throw new Error ('Fibonnci series starts with 0. Please, enter any interget greater than or equal to 0');
}
else if(('number' === typeof num) && num === 0) {
@kavitshah8
kavitshah8 / 2-D-array-fix-2.js
Last active March 17, 2020 10:57
Arrays with one Misc
function createAndInitialize2DArray(size) {
// catch a bug & fix me!
var defaultValue = 0;
var twoDimensionalArray = [];
function initOneDArray() {
var row = [];
for (var i = 0; i < size; i++) {
row.push(defaultValue);
}
@kavitshah8
kavitshah8 / deep-copy.js
Last active October 12, 2015 15:06
Object
function deepCopy(oldObject) {
var temp = JSON.stringify(oldObject);
var newObject = JSON.parse(temp);
return newObject;
}
var employee1 = {
'name': 'Tony',
'age': 27,