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
numArr = [1,2,4,5,3,6,10,11,5,20,50,33,29]; | |
sortAscending = numArr.sort(function(a,b) { | |
return a - b; | |
}); | |
console.log(sortAscending); | |
sortDescending = numArr.sort(function(a,b){ | |
return b - a; |
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
Array.prototype.max = function(){ | |
return this.reduce(function(prev,curr) { | |
return Math.max(prev,curr); | |
}); | |
} | |
arr = [1,2,4,3,6,3,7,8,2]; | |
console.log(arr.max()); |
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 this to create a generic function that you can specialize later | |
// This example takes only 1 argument | |
function add(firstNumber) { | |
//var addMe = firstNumber; | |
return function(secondNumber) { | |
return firstNumber + secondNumber; | |
} | |
} | |
var twenty = add(12)(8); |
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
String.prototype.padLeft = function(padding, passedChar) { | |
if(passedChar === undefined) { | |
passedChar = " "; | |
} | |
var specialChar = passedChar; | |
var strLength = this.length; | |
var padLength = padding - strLength; | |
NewerOlder