Skip to content

Instantly share code, notes, and snippets.

@phette23
Last active April 24, 2021 15:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phette23/9190458 to your computer and use it in GitHub Desktop.
Save phette23/9190458 to your computer and use it in GitHub Desktop.
A few JavaScript One-Liners
// taken from https://medium.com/html5-css3/7c80a4b731f8
// and expanded, unreadable one-liners are kind of pointless
//pad zeroes
function pad(num) {
return ('0' + num).split('').reverse().splice(0,2).reverse().join('')
}
// get page query params
var qp = document.location.search.replace(/(^\?)/,'')
.split("&").map( function (n) {
return n=n.split('='), this[n[0]]=n[1], this;
}.bind({}))[0];
// my own
// return random member of array
rand = function (array) {
return array[Math.floor(Math.random() * array.length)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment