function L337(str) {
return str.replace(/[a-z]/g, function f(a) {
return "4BCD3F6H1JKLMN0PQR57"[parseInt(a, 36) - 10] || a.replace(/[a-t]/gi, f);
});
}
Author: Markandey Singh / Source: JSOneLiners
function pad(num, length) {
return (Array(length).join('0') + num).slice(-length);
}
pad(6, 2) // 06
pad(13, 10) // 0000000013
console.log(["10", "10", "10"].map(parseInt));
// return [10, NaN, 2]
Because why not ?
for (var i = 0, j = 0; i < 10 && j < 10; j++, i = (j == 10) ? i + 1 : i, j = (j == 10) ? j = 0 : j, console.log(i, j)) {}
Author: Nicholas Ortenzio / Source: Medium
function getQueryParams() {
return document.location.search.replace(/(^\?)/, '').split('&').reduce(function (o, n) {
n = n.split('='); o[n[0]] = n[1]; return o;
}, {});
}
getQueryParams() // {key: "value"}
Author: Nicholas Ortenzio / Source: Medium
[].forEach.call($$("*"), function (a) {
a.style.outline = "1px solid #" + (~~(Math.random() * (1 << 24))).toString(16);
});
Author: Addy Osmani / Source: arqex
var newArray = [].concat(a, b.filter(function (item) {
return a.indexOf(item) < 0;
}));
[1, 2, 3, 4, 5].sort(function () { return Math.random() - 0.5; });
var larget = Math.max.apply(Math, [0, 5, 19, 7, -1]); // 19
var smallest = Math.min.apply(Math, [0, 5, 19, 7, -1]); // -1
Array.apply(null, {length: 10}).map(Number.call, Number); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
var index = [{id: 3}].map(function (e) { return e.id; }).indexOf();
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
function convertDate(time) {
var CustomDate = Function.prototype.bind.apply(Date, [null].concat(time.split(/[\s:-]/)).map(function (v, i) {
return (i === 2 ? --v : v);
}));
return new CustomDate();
}
- Sort those things a little bit