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
'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++) { | |
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
"use strict"; | |
function createHalfPyramid (height) { | |
for (var i = 1; i <= height; i++) { | |
var row = ''; | |
for (var j = 1; j <= (height - i); j++) { | |
row += ' '; | |
} |
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
'use strict'; | |
function BinarySearchTree() { | |
this.root = null; | |
} | |
BinarySearchTree.prototype.insertNode = function (val) { | |
var node = { | |
data : val, |
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.first = null; | |
this.last = null; | |
} | |
Queue.prototype.enqueue = function (val) { | |
var q1 = { | |
data : val, | |
next : null |
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
'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. |
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
class LinkedList { | |
constructor() { | |
this.head = null; | |
} | |
insertNodeAtTail(val) { | |
var node = { | |
data: val, |
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
name = 'Kavit'; | |
var team = { | |
name: 'Kevin', | |
member: { | |
name: 'Nik', | |
getName: function () { | |
return this.name; | |
} | |
} |
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
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) { |
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 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); | |
} |
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 deepCopy(oldObject) { | |
var temp = JSON.stringify(oldObject); | |
var newObject = JSON.parse(temp); | |
return newObject; | |
} | |
var employee1 = { | |
'name': 'Tony', | |
'age': 27, |