Skip to content

Instantly share code, notes, and snippets.

View jslnriot's full-sized avatar

James Buczkowski jslnriot

View GitHub Profile
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;
@jslnriot
jslnriot / maxInArray.js
Created April 8, 2016 01:01
create a function that gets the max number in an array
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());
// 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);
@jslnriot
jslnriot / padLeft.js
Created March 30, 2016 01:13
padLeft
String.prototype.padLeft = function(padding, passedChar) {
if(passedChar === undefined) {
passedChar = " ";
}
var specialChar = passedChar;
var strLength = this.length;
var padLength = padding - strLength;