Skip to content

Instantly share code, notes, and snippets.

@Tedko
Last active September 27, 2016 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tedko/c2d0d57f3a292f4a11445f0322f6e934 to your computer and use it in GitHub Desktop.
Save Tedko/c2d0d57f3a292f4a11445f0322f6e934 to your computer and use it in GitHub Desktop.
js cheapsheet
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