This file contains hidden or 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
const countNegative = ( M, n, m ) => { | |
var count = 0; | |
// start from top right | |
var i = 0; | |
var j = m - 1; | |
while ( j >= 0 && i < n ) { | |
if ( M[i][j] < 0 ) { | |
// last negative number is at index j. Hence, there j + 1 negative numebrs at index i |
This file contains hidden or 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 realSum(a, b) { | |
return a + b; | |
}; | |
console.log(realSum(5, 3)); // 8 | |
var sum5 = curryIt(realSum, 5); | |
console.log(sum5(4)); // 9 |
This file contains hidden or 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 curryIt = function(fn) { | |
var fnArgsWhileBeingCurried = Array.prototype.slice.call(arguments, 1); | |
return function() { | |
var fnArgsAfterBeingCurried = Array.prototype.slice.call(arguments, 0); | |
return fn.apply(this, fnArgsWhileBeingCurried.concat(fnArgsAfterBeingCurried)); | |
}; | |
}; |
This file contains hidden or 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 realSum(a, b) { | |
return a + b; | |
}; | |
function sum(a, b) { | |
return b ? | |
realSum(a, b) : | |
function(b) { | |
// This anonymous function has access to variable `a` via closure |
This file contains hidden or 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 flattenThreeLevelNestedTree() { | |
var movieLists = [{ | |
name: "Instant Queue", | |
videos: [{ | |
"id": 70111470, | |
"title": "Die Hard", | |
"boxarts": [{ | |
width: 150, |
This file contains hidden or 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 commonAncestor(n1, n2) { | |
var inOrderTra = inOrder(this); | |
var postOrderTra = postOrder(this); | |
var i1 = inOrderTra.indexOf(n1); | |
var i2 = inOrderTra.indexOf(n2); | |
var middleNodes = inOrderTra.splice(i1 + 1, i2); |
This file contains hidden or 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 inOrderSuccessor(node) { | |
if (!node) { | |
return null; | |
} | |
if (node.right) { | |
return leftMostChild(node.right); | |
} else { |
This file contains hidden or 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'; | |
Array.prototype.zip = function(left, right, combinerFunction) { | |
let results, length; | |
length = Math.min(left.length, right.length); | |
results = []; | |
for (let i = 0; i < length; i++) { | |
results.push(combinerFunction(left[i], right[i])); |
This file contains hidden or 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'; | |
Array.prototype.zip = function(left, right, combinerFunction) { | |
let results, length; | |
length = Math.min(left.length, right.length); | |
results = []; | |
for (let i = 0; i < length; i++) { | |
results.push(combinerFunction(left[i], right[i])); | |
} |
This file contains hidden or 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 zip() { | |
var videos = [{ | |
"id": 70111470, | |
"title": "Die Hard", | |
"rating": 4.0, | |
}, { | |
"id": 654356453, | |
"title": "Bad Boys", |