Last active
September 27, 2016 03:12
-
-
Save Tedko/c2d0d57f3a292f4a11445f0322f6e934 to your computer and use it in GitHub Desktop.
js cheapsheet
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 makeArray(w, h, val) { | |
var arr = []; | |
for(i = 0; i < h; i++) { | |
arr[i] = []; | |
for(j = 0; j < w; j++) { | |
arr[i][j] = val; | |
} | |
} | |
return arr; | |
} | |
//split a str by whitespace and ignr lead & tail white space | |
str.match(/\S+/g) || [] | |
//Max & Min of a Double Array | |
//arr = [[]] | |
var max=0;//VERY SMALL VALUE | |
arr.forEach(function(row){ | |
row.forEach(function(elem){ | |
max = Math.max(max,elem) | |
}) | |
}); | |
//Remove Leading 0 in string | |
s.replace(/\b0+/g, '') | |
//SORT | |
//[ [ 2, 4 ], [ 4, 1 ], [ 8, 8 ], [ 3, 5 ] ] | |
points = points.sort((pnt, pnt2) => pnt[0] > pnt2[0]) | |
//[ [ 2, 4 ], [ 3, 5 ], [ 4, 1 ], [ 8, 8 ] ] | |
num.sort((a,b)=>a>b) | |
//[1, 3, 12] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment