This file contains hidden or 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
Array.prototype.transpose = function () { | |
return this.length === 0 ? this : this[0].map((col, i) => this.map((row) => row[i])) | |
} |
This file contains hidden or 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
const multilevelsort = (records, order) => records.sort(chainSortBy(order)) | |
const sort_by = ({ key, direction }) => { | |
return function (a, b) { | |
a = a[key] | |
b = b[key] | |
return a == b ? 0 : [-1, 1][+(direction === 'ascending')] * ((a > b) - (b > a)) | |
} | |
} |
This file contains hidden or 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
const getNthHamming = n => getHammingNumbers(n).reverse()[0] | |
const getHammingNumbers = n => { | |
let numbers = [] | |
let next = 1 | |
while (numbers.length < n) { | |
if (isHammingNumber(next)) | |
numbers.push(next) | |
This file contains hidden or 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
/** | |
* Creates an object of groupings. | |
* | |
* @param {Function|String} f - The function that returns value to group by or object key. | |
* @returns {Object} Returns the composed aggregate object. | |
* @example | |
* | |
* array.groupBy('city'); | |
* array.groupBy(function (obj) { return obj.city; }); | |
* array.groupBy((obj) => { return obj.city; }); |
This file contains hidden or 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
var DI = function () { | |
let _deps = {} | |
this.dep = (name, func) => { _deps[name] = func } | |
this.getDep = (name) => _deps[name] | |
} | |
DI.prototype.inject = function (fn) { | |
let fnString = fn.toString().replace(/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg, ''), | |
paramNames = fnString.split('(')[1].split(')')[0].split(',').map(v => v.trim()), |
This file contains hidden or 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
html { | |
-webkit-font-smoothing: antialiased; | |
} | |
body { | |
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif; | |
line-height: 1.5; | |
} | |
h1, h2, h3, h4, h5, h6 { |
OlderNewer