ran npm run tdd
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
module.exports = JSONToDate = arr => {
|
const JSONToDate = arr => {
|
||||||
const dt = new Date(parseInt(arr.toString().substr(6)));
|
const dt = new Date(parseInt(arr.toString().substr(6)));
|
||||||
return `${dt.getDate()}/${dt.getMonth() + 1}/${dt.getFullYear()}`;
|
return `${dt.getDate()}/${dt.getMonth() + 1}/${dt.getFullYear()}`;
|
||||||
};
|
};
|
||||||
|
module.exports = JSONToDate
|
||||||
4
test/JSONToFile/JSONToFile.js
Normal file
4
test/JSONToFile/JSONToFile.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const JSONToFile = (obj, filename) =>
|
||||||
|
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
|
||||||
|
module.exports = JSONToFile
|
||||||
13
test/JSONToFile/JSONToFile.test.js
Normal file
13
test/JSONToFile/JSONToFile.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const JSONToFile = require('./JSONToFile.js');
|
||||||
|
|
||||||
|
test('Testing JSONToFile', (t) => {
|
||||||
|
//For more information on all the methods supported by tape
|
||||||
|
//Please go to https://github.com/substack/tape
|
||||||
|
t.true(typeof JSONToFile === 'function', 'JSONToFile is a Function');
|
||||||
|
//t.deepEqual(JSONToFile(args..), 'Expected');
|
||||||
|
//t.equal(JSONToFile(args..), 'Expected');
|
||||||
|
//t.false(JSONToFile(args..), 'Expected');
|
||||||
|
//t.throws(JSONToFile(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
|
const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
|
||||||
|
module.exports = RGBToHex
|
||||||
@ -1,8 +1,10 @@
|
|||||||
module.exports = URLJoin = (...args) =>
|
const URLJoin = (...args) =>
|
||||||
args.join('/')
|
args
|
||||||
.replace(/[\/]+/g,'/')
|
.join('/')
|
||||||
.replace(/^(.+):\//,'$1://')
|
.replace(/[\/]+/g, '/')
|
||||||
.replace(/^file:/,'file:/')
|
.replace(/^(.+):\//, '$1://')
|
||||||
|
.replace(/^file:/, 'file:/')
|
||||||
.replace(/\/(\?|&|#[^!])/g, '$1')
|
.replace(/\/(\?|&|#[^!])/g, '$1')
|
||||||
.replace(/\?/g,'&')
|
.replace(/\?/g, '&')
|
||||||
.replace('&','?');
|
.replace('&', '?');
|
||||||
|
module.exports = URLJoin
|
||||||
@ -1,4 +1,5 @@
|
|||||||
module.exports = UUIDGeneratorBrowser = () =>
|
const UUIDGeneratorBrowser = () =>
|
||||||
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
||||||
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
|
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
|
||||||
);
|
);
|
||||||
|
module.exports = UUIDGeneratorBrowser
|
||||||
6
test/UUIDGeneratorNode/UUIDGeneratorNode.js
Normal file
6
test/UUIDGeneratorNode/UUIDGeneratorNode.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
const crypto = require('crypto');
|
||||||
|
const UUIDGeneratorNode = () =>
|
||||||
|
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
||||||
|
(c ^ (crypto.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
|
||||||
|
);
|
||||||
|
module.exports = UUIDGeneratorNode
|
||||||
13
test/UUIDGeneratorNode/UUIDGeneratorNode.test.js
Normal file
13
test/UUIDGeneratorNode/UUIDGeneratorNode.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const UUIDGeneratorNode = require('./UUIDGeneratorNode.js');
|
||||||
|
|
||||||
|
test('Testing UUIDGeneratorNode', (t) => {
|
||||||
|
//For more information on all the methods supported by tape
|
||||||
|
//Please go to https://github.com/substack/tape
|
||||||
|
t.true(typeof UUIDGeneratorNode === 'function', 'UUIDGeneratorNode is a Function');
|
||||||
|
//t.deepEqual(UUIDGeneratorNode(args..), 'Expected');
|
||||||
|
//t.equal(UUIDGeneratorNode(args..), 'Expected');
|
||||||
|
//t.false(UUIDGeneratorNode(args..), 'Expected');
|
||||||
|
//t.throws(UUIDGeneratorNode(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = anagrams = str => {
|
const anagrams = str => {
|
||||||
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
|
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
|
||||||
return str
|
return str
|
||||||
.split('')
|
.split('')
|
||||||
@ -7,4 +7,5 @@ return str
|
|||||||
acc.concat(anagrams(str.slice(0, i) + str.slice(i + 1)).map(val => letter + val)),
|
acc.concat(anagrams(str.slice(0, i) + str.slice(i + 1)).map(val => letter + val)),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
module.exports = anagrams
|
||||||
@ -1,2 +1,3 @@
|
|||||||
module.exports = arrayToHtmlList = (arr, listID) =>
|
const arrayToHtmlList = (arr, listID) =>
|
||||||
arr.map(item => (document.querySelector('#' + listID).innerHTML += `<li>${item}</li>`));
|
arr.map(item => (document.querySelector('#' + listID).innerHTML += `<li>${item}</li>`));
|
||||||
|
module.exports = arrayToHtmlList
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = average = (...nums) => [...nums].reduce((acc, val) => acc + val, 0) / nums.length;
|
const average = (...nums) => [...nums].reduce((acc, val) => acc + val, 0) / nums.length;
|
||||||
|
module.exports = average
|
||||||
@ -1,3 +1,4 @@
|
|||||||
module.exports = averageBy = (arr, fn) =>
|
const averageBy = (arr, fn) =>
|
||||||
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0) /
|
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0) /
|
||||||
arr.length;
|
arr.length;
|
||||||
|
module.exports = averageBy
|
||||||
@ -1,7 +1,8 @@
|
|||||||
module.exports = binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
|
const binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
|
||||||
if (start > end) return -1;
|
if (start > end) return -1;
|
||||||
const mid = Math.floor((start + end) / 2);
|
const mid = Math.floor((start + end) / 2);
|
||||||
if (arr[mid] > val) return binarySearch(arr, val, start, mid - 1);
|
if (arr[mid] > val) return binarySearch(arr, val, start, mid - 1);
|
||||||
if (arr[mid] < val) return binarySearch(arr, val, mid + 1, end);
|
if (arr[mid] < val) return binarySearch(arr, val, mid + 1, end);
|
||||||
return mid;
|
return mid;
|
||||||
}
|
}
|
||||||
|
module.exports = binarySearch
|
||||||
@ -1,3 +1,4 @@
|
|||||||
module.exports = bottomVisible = () =>
|
const bottomVisible = () =>
|
||||||
document.documentElement.clientHeight + window.scrollY >=
|
document.documentElement.clientHeight + window.scrollY >=
|
||||||
(document.documentElement.scrollHeight || document.documentElement.clientHeight);
|
(document.documentElement.scrollHeight || document.documentElement.clientHeight);
|
||||||
|
module.exports = bottomVisible
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = byteSize = str => new Blob([str]).size;
|
const byteSize = str => new Blob([str]).size;
|
||||||
|
module.exports = byteSize
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = call = (key, ...args) => context => context[key](...args);
|
const call = (key, ...args) => context => context[key](...args);
|
||||||
|
module.exports = call
|
||||||
@ -1,2 +1,3 @@
|
|||||||
module.exports = capitalize = ([first, ...rest], lowerRest = false) =>
|
const capitalize = ([first, ...rest], lowerRest = false) =>
|
||||||
first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join(''));
|
first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join(''));
|
||||||
|
module.exports = capitalize
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperCase());
|
const capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperCase());
|
||||||
|
module.exports = capitalizeEveryWord
|
||||||
@ -1,5 +1,6 @@
|
|||||||
module.exports = chainAsync = fns => {
|
const chainAsync = fns => {
|
||||||
let curr = 0;
|
let curr = 0;
|
||||||
const next = () => fns[curr++](next);
|
const next = () => fns[curr++](next);
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
module.exports = chainAsync
|
||||||
@ -1,4 +1,5 @@
|
|||||||
module.exports = chunk = (arr, size) =>
|
const chunk = (arr, size) =>
|
||||||
Array.from({ length: Math.ceil(arr.length / size) }, (v, i) =>
|
Array.from({ length: Math.ceil(arr.length / size) }, (v, i) =>
|
||||||
arr.slice(i * size, i * size + size)
|
arr.slice(i * size, i * size + size)
|
||||||
);
|
);
|
||||||
|
module.exports = chunk
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
|
const clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
|
||||||
|
module.exports = clampNumber
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = cleanObj = (obj, keysToKeep = [], childIndicator) => {
|
const cleanObj = (obj, keysToKeep = [], childIndicator) => {
|
||||||
Object.keys(obj).forEach(key => {
|
Object.keys(obj).forEach(key => {
|
||||||
if (key === childIndicator) {
|
if (key === childIndicator) {
|
||||||
cleanObj(obj[key], keysToKeep, childIndicator);
|
cleanObj(obj[key], keysToKeep, childIndicator);
|
||||||
@ -7,4 +7,5 @@ delete obj[key];
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
module.exports = cleanObj
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
|
const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
|
||||||
|
module.exports = cloneRegExp
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = coalesce = (...args) => args.find(_ => ![undefined, null].includes(_));
|
const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_));
|
||||||
|
module.exports = coalesce
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = coalesceFactory = valid => (...args) => args.find(valid);
|
const coalesceFactory = valid => (...args) => args.find(valid);
|
||||||
|
module.exports = coalesceFactory
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = collatz = n => (n % 2 == 0 ? n / 2 : 3 * n + 1);
|
const collatz = n => (n % 2 == 0 ? n / 2 : 3 * n + 1);
|
||||||
|
module.exports = collatz
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = collectInto = fn => (...args) => fn(args);
|
const collectInto = fn => (...args) => fn(args);
|
||||||
|
module.exports = collectInto
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = colorize = (...args) => ({
|
const colorize = (...args) => ({
|
||||||
black: `\x1b[30m${args.join(' ')}`,
|
black: `\x1b[30m${args.join(' ')}`,
|
||||||
red: `\x1b[31m${args.join(' ')}`,
|
red: `\x1b[31m${args.join(' ')}`,
|
||||||
green: `\x1b[32m${args.join(' ')}`,
|
green: `\x1b[32m${args.join(' ')}`,
|
||||||
@ -15,4 +15,5 @@ bgBlue: `\x1b[44m${args.join(' ')}\x1b[0m`,
|
|||||||
bgMagenta: `\x1b[45m${args.join(' ')}\x1b[0m`,
|
bgMagenta: `\x1b[45m${args.join(' ')}\x1b[0m`,
|
||||||
bgCyan: `\x1b[46m${args.join(' ')}\x1b[0m`,
|
bgCyan: `\x1b[46m${args.join(' ')}\x1b[0m`,
|
||||||
bgWhite: `\x1b[47m${args.join(' ')}\x1b[0m`
|
bgWhite: `\x1b[47m${args.join(' ')}\x1b[0m`
|
||||||
});
|
});
|
||||||
|
module.exports = colorize
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = compact = arr => arr.filter(Boolean);
|
const compact = arr => arr.filter(Boolean);
|
||||||
|
module.exports = compact
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
|
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
|
||||||
|
module.exports = compose
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = copyToClipboard = str => {
|
const copyToClipboard = str => {
|
||||||
const el = document.createElement('textarea');
|
const el = document.createElement('textarea');
|
||||||
el.value = str;
|
el.value = str;
|
||||||
el.setAttribute('readonly', '');
|
el.setAttribute('readonly', '');
|
||||||
@ -14,4 +14,5 @@ if (selected) {
|
|||||||
document.getSelection().removeAllRanges();
|
document.getSelection().removeAllRanges();
|
||||||
document.getSelection().addRange(selected);
|
document.getSelection().addRange(selected);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
module.exports = copyToClipboard
|
||||||
@ -1,5 +1,6 @@
|
|||||||
module.exports = countBy = (arr, fn) =>
|
const countBy = (arr, fn) =>
|
||||||
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val, i) => {
|
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val, i) => {
|
||||||
acc[val] = (acc[val] || 0) + 1;
|
acc[val] = (acc[val] || 0) + 1;
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
module.exports = countBy
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a + 0), 0);
|
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a + 0), 0);
|
||||||
|
module.exports = countOccurrences
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = countVowels = str => (str.match(/[aeiou]/gi) || []).length;
|
const countVowels = str => (str.match(/[aeiou]/gi) || []).length;
|
||||||
|
module.exports = countVowels
|
||||||
@ -1,5 +1,6 @@
|
|||||||
module.exports = createElement = str => {
|
const createElement = str => {
|
||||||
const el = document.createElement('div');
|
const el = document.createElement('div');
|
||||||
el.innerHTML = str;
|
el.innerHTML = str;
|
||||||
return el.firstElementChild;
|
return el.firstElementChild;
|
||||||
};
|
};
|
||||||
|
module.exports = createElement
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = createEventHub = () => ({
|
const createEventHub = () => ({
|
||||||
hub: Object.create(null),
|
hub: Object.create(null),
|
||||||
emit(event, data) {
|
emit(event, data) {
|
||||||
(this.hub[event] || []).forEach(handler => handler(data));
|
(this.hub[event] || []).forEach(handler => handler(data));
|
||||||
@ -11,4 +11,5 @@ off(event, handler) {
|
|||||||
const i = (this.hub[event] || []).findIndex(h => h === handler);
|
const i = (this.hub[event] || []).findIndex(h => h === handler);
|
||||||
if (i > -1) this.hub[event].splice(i, 1);
|
if (i > -1) this.hub[event].splice(i, 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
module.exports = createEventHub
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = currentURL = () => window.location.href;
|
const currentURL = () => window.location.href;
|
||||||
|
module.exports = currentURL
|
||||||
@ -1,2 +1,3 @@
|
|||||||
module.exports = curry = (fn, arity = fn.length, ...args) =>
|
const curry = (fn, arity = fn.length, ...args) =>
|
||||||
arity <= args.length ? fn(...args) : curry.bind(null, fn, arity, ...args);
|
arity <= args.length ? fn(...args) : curry.bind(null, fn, arity, ...args);
|
||||||
|
module.exports = curry
|
||||||
@ -1,2 +1,3 @@
|
|||||||
module.exports = decapitalize = ([first, ...rest], upperRest = false) =>
|
const decapitalize = ([first, ...rest], upperRest = false) =>
|
||||||
first.toLowerCase() + (upperRest ? rest.join('').toUpperCase() : rest.join(''));
|
first.toLowerCase() + (upperRest ? rest.join('').toUpperCase() : rest.join(''));
|
||||||
|
module.exports = decapitalize
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
|
const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
|
||||||
|
module.exports = deepFlatten
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = defer = (fn, ...args) => setTimeout(fn, 1, ...args);
|
const defer = (fn, ...args) => setTimeout(fn, 1, ...args);
|
||||||
|
module.exports = defer
|
||||||
@ -1,4 +1,5 @@
|
|||||||
module.exports = detectDeviceType = () =>
|
const detectDeviceType = () =>
|
||||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
|
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
|
||||||
? 'Mobile'
|
? 'Mobile'
|
||||||
: 'Desktop';
|
: 'Desktop';
|
||||||
|
module.exports = detectDeviceType
|
||||||
@ -1,4 +1,5 @@
|
|||||||
module.exports = difference = (a, b) => {
|
const difference = (a, b) => {
|
||||||
const s = new Set(b);
|
const s = new Set(b);
|
||||||
return a.filter(x => !s.has(x));
|
return a.filter(x => !s.has(x));
|
||||||
};
|
};
|
||||||
|
module.exports = difference
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = differenceWith = (arr, val, comp) => arr.filter(a => val.findIndex(b => comp(a, b)) === -1);
|
const differenceWith = (arr, val, comp) => arr.filter(a => val.findIndex(b => comp(a, b)) === -1);
|
||||||
|
module.exports = differenceWith
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = digitize = n => [...`${n}`].map(i => parseInt(i));
|
const digitize = n => [...`${n}`].map(i => parseInt(i));
|
||||||
|
module.exports = digitize
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
|
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
|
||||||
|
module.exports = distance
|
||||||
@ -1,4 +1,5 @@
|
|||||||
module.exports = dropElements = (arr, func) => {
|
const dropElements = (arr, func) => {
|
||||||
while (arr.length > 0 && !func(arr[0])) arr = arr.slice(1);
|
while (arr.length > 0 && !func(arr[0])) arr = arr.slice(1);
|
||||||
return arr;
|
return arr;
|
||||||
};
|
};
|
||||||
|
module.exports = dropElements
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = dropRight = (arr, n = 1) => arr.slice(0, -n);
|
const dropRight = (arr, n = 1) => arr.slice(0, -n);
|
||||||
|
module.exports = dropRight
|
||||||
@ -1,8 +1,9 @@
|
|||||||
module.exports = elementIsVisibleInViewport = (el, partiallyVisible = false) => {
|
const elementIsVisibleInViewport = (el, partiallyVisible = false) => {
|
||||||
const { top, left, bottom, right } = el.getBoundingClientRect();
|
const { top, left, bottom, right } = el.getBoundingClientRect();
|
||||||
const { innerHeight, innerWidth } = window;
|
const { innerHeight, innerWidth } = window;
|
||||||
return partiallyVisible
|
return partiallyVisible
|
||||||
? ((top > 0 && top < innerHeight) || (bottom > 0 && bottom < innerHeight)) &&
|
? ((top > 0 && top < innerHeight) || (bottom > 0 && bottom < innerHeight)) &&
|
||||||
((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth))
|
((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth))
|
||||||
: top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
|
: top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
|
||||||
};
|
};
|
||||||
|
module.exports = elementIsVisibleInViewport
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = elo = ([...ratings], kFactor = 32, selfRating) => {
|
const elo = ([...ratings], kFactor = 32, selfRating) => {
|
||||||
const [a, b] = ratings;
|
const [a, b] = ratings;
|
||||||
const expectedScore = (self, opponent) => 1 / (1 + 10 ** ((opponent - self) / 400));
|
const expectedScore = (self, opponent) => 1 / (1 + 10 ** ((opponent - self) / 400));
|
||||||
const newRating = (rating, i) =>
|
const newRating = (rating, i) =>
|
||||||
@ -15,4 +15,5 @@ j++;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ratings;
|
return ratings;
|
||||||
};
|
};
|
||||||
|
module.exports = elo
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = equals = (a, b) => {
|
const equals = (a, b) => {
|
||||||
if (a === b) return true;
|
if (a === b) return true;
|
||||||
if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
|
if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
|
||||||
if (!a || !b || (typeof a != 'object' && typeof b !== 'object')) return a === b;
|
if (!a || !b || (typeof a != 'object' && typeof b !== 'object')) return a === b;
|
||||||
@ -7,4 +7,5 @@ if (a.prototype !== b.prototype) return false;
|
|||||||
let keys = Object.keys(a);
|
let keys = Object.keys(a);
|
||||||
if (keys.length !== Object.keys(b).length) return false;
|
if (keys.length !== Object.keys(b).length) return false;
|
||||||
return keys.every(k => equals(a[k], b[k]));
|
return keys.every(k => equals(a[k], b[k]));
|
||||||
};
|
};
|
||||||
|
module.exports = equals
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = escapeHTML = str =>
|
const escapeHTML = str =>
|
||||||
str.replace(
|
str.replace(
|
||||||
/[&<>'"]/g,
|
/[&<>'"]/g,
|
||||||
tag =>
|
tag =>
|
||||||
@ -9,4 +9,5 @@ tag =>
|
|||||||
"'": ''',
|
"'": ''',
|
||||||
'"': '"'
|
'"': '"'
|
||||||
}[tag] || tag)
|
}[tag] || tag)
|
||||||
);
|
);
|
||||||
|
module.exports = escapeHTML
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
|
module.exports = escapeRegExp
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = everyNth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1);
|
const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1);
|
||||||
|
module.exports = everyNth
|
||||||
@ -1,7 +1,8 @@
|
|||||||
module.exports = extendHex = shortHex =>
|
const extendHex = shortHex =>
|
||||||
'#' +
|
'#' +
|
||||||
shortHex
|
shortHex
|
||||||
.slice(shortHex.startsWith('#') ? 1 : 0)
|
.slice(shortHex.startsWith('#') ? 1 : 0)
|
||||||
.split('')
|
.split('')
|
||||||
.map(x => x + x)
|
.map(x => x + x)
|
||||||
.join('');
|
.join('');
|
||||||
|
module.exports = extendHex
|
||||||
@ -1,6 +1,7 @@
|
|||||||
module.exports = factorial = n =>
|
const factorial = n =>
|
||||||
n < 0
|
n < 0
|
||||||
? (() => {
|
? (() => {
|
||||||
throw new TypeError('Negative numbers are not allowed!');
|
throw new TypeError('Negative numbers are not allowed!');
|
||||||
})()
|
})()
|
||||||
: n <= 1 ? 1 : n * factorial(n - 1);
|
: n <= 1 ? 1 : n * factorial(n - 1);
|
||||||
|
module.exports = factorial
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = factors = (num, primes = false) => {
|
const factors = (num, primes = false) => {
|
||||||
const isPrime = num => {
|
const isPrime = num => {
|
||||||
const boundary = Math.floor(Math.sqrt(num));
|
const boundary = Math.floor(Math.sqrt(num));
|
||||||
for (var i = 2; i <= boundary; i++) if (num % i === 0) return false;
|
for (var i = 2; i <= boundary; i++) if (num % i === 0) return false;
|
||||||
@ -16,4 +16,5 @@ acc.push(-val);
|
|||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
return primes ? array.filter(isPrime) : array;
|
return primes ? array.filter(isPrime) : array;
|
||||||
};
|
};
|
||||||
|
module.exports = factors
|
||||||
@ -1,5 +1,6 @@
|
|||||||
module.exports = fibonacci = n =>
|
const fibonacci = n =>
|
||||||
Array.from({ length: n }).reduce(
|
Array.from({ length: n }).reduce(
|
||||||
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
|
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
module.exports = fibonacci
|
||||||
@ -1,2 +1,3 @@
|
|||||||
module.exports = fibonacciCountUntilNum = num =>
|
const fibonacciCountUntilNum = num =>
|
||||||
Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));
|
Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));
|
||||||
|
module.exports = fibonacciCountUntilNum
|
||||||
@ -1,7 +1,8 @@
|
|||||||
module.exports = fibonacciUntilNum = num => {
|
const fibonacciUntilNum = num => {
|
||||||
let n = Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));
|
let n = Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));
|
||||||
return Array.from({ length: n }).reduce(
|
return Array.from({ length: n }).reduce(
|
||||||
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
|
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
module.exports = fibonacciUntilNum
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i));
|
const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i));
|
||||||
|
module.exports = filterNonUnique
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = findLast = (arr, fn) => arr.filter(fn).slice(-1);
|
const findLast = (arr, fn) => arr.filter(fn).slice(-1);
|
||||||
|
module.exports = findLast
|
||||||
@ -1,4 +1,5 @@
|
|||||||
module.exports = flatten = (arr, depth = 1) =>
|
const flatten = (arr, depth = 1) =>
|
||||||
depth != 1
|
depth != 1
|
||||||
? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flatten(v, depth - 1) : v), [])
|
? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flatten(v, depth - 1) : v), [])
|
||||||
: arr.reduce((a, v) => a.concat(v), []);
|
: arr.reduce((a, v) => a.concat(v), []);
|
||||||
|
module.exports = flatten
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = flip = fn => (...args) => fn(args.pop(), ...args);
|
const flip = fn => (...args) => fn(args.pop(), ...args);
|
||||||
|
module.exports = flip
|
||||||
@ -1,5 +1,6 @@
|
|||||||
module.exports = forEachRight = (arr, callback) =>
|
const forEachRight = (arr, callback) =>
|
||||||
arr
|
arr
|
||||||
.slice(0)
|
.slice(0)
|
||||||
.reverse()
|
.reverse()
|
||||||
.forEach(callback);
|
.forEach(callback);
|
||||||
|
module.exports = forEachRight
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = formatDuration = ms => {
|
const formatDuration = ms => {
|
||||||
if (ms < 0) ms = -ms;
|
if (ms < 0) ms = -ms;
|
||||||
const time = {
|
const time = {
|
||||||
day: Math.floor(ms / 86400000),
|
day: Math.floor(ms / 86400000),
|
||||||
@ -11,4 +11,5 @@ return Object.entries(time)
|
|||||||
.filter(val => val[1] !== 0)
|
.filter(val => val[1] !== 0)
|
||||||
.map(val => val[1] + ' ' + (val[1] !== 1 ? val[0] + 's' : val[0]))
|
.map(val => val[1] + ' ' + (val[1] !== 1 ? val[0] + 's' : val[0]))
|
||||||
.join(', ');
|
.join(', ');
|
||||||
};
|
};
|
||||||
|
module.exports = formatDuration
|
||||||
@ -1,5 +1,6 @@
|
|||||||
module.exports = fromCamelCase = (str, separator = '_') =>
|
const fromCamelCase = (str, separator = '_') =>
|
||||||
str
|
str
|
||||||
.replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2')
|
.replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2')
|
||||||
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + separator + '$2')
|
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + separator + '$2')
|
||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
|
module.exports = fromCamelCase
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = functionName = fn => (console.debug(fn.name), fn);
|
const functionName = fn => (console.debug(fn.name), fn);
|
||||||
|
module.exports = functionName
|
||||||
@ -1,5 +1,6 @@
|
|||||||
module.exports = functions = (obj, inherited = false) =>
|
const functions = (obj, inherited = false) =>
|
||||||
(inherited
|
(inherited
|
||||||
? [...Object.keys(obj), ...Object.keys(Object.getPrototypeOf(obj))]
|
? [...Object.keys(obj), ...Object.keys(Object.getPrototypeOf(obj))]
|
||||||
: Object.keys(obj)
|
: Object.keys(obj)
|
||||||
).filter(key => typeof obj[key] === 'function');
|
).filter(key => typeof obj[key] === 'function');
|
||||||
|
module.exports = functions
|
||||||
@ -1,4 +1,5 @@
|
|||||||
module.exports = gcd = (...arr) => {
|
const gcd = (...arr) => {
|
||||||
const _gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
const _gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
||||||
return [...arr].reduce((a, b) => _gcd(a, b));
|
return [...arr].reduce((a, b) => _gcd(a, b));
|
||||||
};
|
};
|
||||||
|
module.exports = gcd
|
||||||
@ -1,4 +1,5 @@
|
|||||||
module.exports = geometricProgression = (end, start = 1, step = 2) =>
|
const geometricProgression = (end, start = 1, step = 2) =>
|
||||||
Array.from({ length: Math.floor(Math.log(end / start) / Math.log(step)) + 1 }).map(
|
Array.from({ length: Math.floor(Math.log(end / start) / Math.log(step)) + 1 }).map(
|
||||||
(v, i) => start * step ** i
|
(v, i) => start * step ** i
|
||||||
);
|
);
|
||||||
|
module.exports = geometricProgression
|
||||||
@ -1,2 +1,3 @@
|
|||||||
module.exports = getDaysDiffBetweenDates = (dateInitial, dateFinal) =>
|
const getDaysDiffBetweenDates = (dateInitial, dateFinal) =>
|
||||||
(dateFinal - dateInitial) / (1000 * 3600 * 24);
|
(dateFinal - dateInitial) / (1000 * 3600 * 24);
|
||||||
|
module.exports = getDaysDiffBetweenDates
|
||||||
@ -1,4 +1,5 @@
|
|||||||
module.exports = getScrollPosition = (el = window) => ({
|
const getScrollPosition = (el = window) => ({
|
||||||
x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft,
|
x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft,
|
||||||
y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop
|
y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop
|
||||||
});
|
});
|
||||||
|
module.exports = getScrollPosition
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = getStyle = (el, ruleName) => getComputedStyle(el)[ruleName];
|
const getStyle = (el, ruleName) => getComputedStyle(el)[ruleName];
|
||||||
|
module.exports = getStyle
|
||||||
@ -1,2 +1,3 @@
|
|||||||
module.exports = getType = v =>
|
const getType = v =>
|
||||||
v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase();
|
v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase();
|
||||||
|
module.exports = getType
|
||||||
@ -1,4 +1,5 @@
|
|||||||
module.exports = getURLParameters = url =>
|
const getURLParameters = url =>
|
||||||
url
|
url
|
||||||
.match(/([^?=&]+)(=([^&]*))/g)
|
.match(/([^?=&]+)(=([^&]*))/g)
|
||||||
.reduce((a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a), {});
|
.reduce((a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a), {});
|
||||||
|
module.exports = getURLParameters
|
||||||
@ -1,5 +1,6 @@
|
|||||||
module.exports = groupBy = (arr, fn) =>
|
const groupBy = (arr, fn) =>
|
||||||
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val, i) => {
|
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val, i) => {
|
||||||
acc[val] = (acc[val] || []).concat(arr[i]);
|
acc[val] = (acc[val] || []).concat(arr[i]);
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
module.exports = groupBy
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = hammingDistance = (num1, num2) => ((num1 ^ num2).toString(2).match(/1/g) || '').length;
|
const hammingDistance = (num1, num2) => ((num1 ^ num2).toString(2).match(/1/g) || '').length;
|
||||||
|
module.exports = hammingDistance
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = hasClass = (el, className) => el.classList.contains(className);
|
const hasClass = (el, className) => el.classList.contains(className);
|
||||||
|
module.exports = hasClass
|
||||||
@ -1,2 +1,3 @@
|
|||||||
module.exports = hasFlags = (...flags) =>
|
const hasFlags = (...flags) =>
|
||||||
flags.every(flag => process.argv.includes(/^-{1,2}/.test(flag) ? flag : '--' + flag));
|
flags.every(flag => process.argv.includes(/^-{1,2}/.test(flag) ? flag : '--' + flag));
|
||||||
|
module.exports = hasFlags
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = head = arr => arr[0];
|
const head = arr => arr[0];
|
||||||
|
module.exports = head
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = hexToRGB = hex => {
|
const hexToRGB = hex => {
|
||||||
let alpha = false,
|
let alpha = false,
|
||||||
h = hex.slice(hex.startsWith('#') ? 1 : 0);
|
h = hex.slice(hex.startsWith('#') ? 1 : 0);
|
||||||
if (h.length === 3) h = [...h].map(x => x + x).join('');
|
if (h.length === 3) h = [...h].map(x => x + x).join('');
|
||||||
@ -16,4 +16,5 @@ return (
|
|||||||
(alpha ? `, ${h & 0x000000ff}` : '') +
|
(alpha ? `, ${h & 0x000000ff}` : '') +
|
||||||
')'
|
')'
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
module.exports = hexToRGB
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = hide = (...el) => [...el].forEach(e => (e.style.display = 'none'));
|
const hide = (...el) => [...el].forEach(e => (e.style.display = 'none'));
|
||||||
|
module.exports = hide
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module.exports = howManyTimes = (num, divisor) => {
|
const howManyTimes = (num, divisor) => {
|
||||||
if (divisor === 1 || divisor === -1) return Infinity;
|
if (divisor === 1 || divisor === -1) return Infinity;
|
||||||
if (divisor === 0) return 0;
|
if (divisor === 0) return 0;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
@ -7,4 +7,5 @@ i++;
|
|||||||
num = num / divisor;
|
num = num / divisor;
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
};
|
};
|
||||||
|
module.exports = howManyTimes
|
||||||
@ -1,7 +1,8 @@
|
|||||||
module.exports = httpDelete = (url, callback, err = console.error) => {
|
const httpDelete = (url, callback, err = console.error) => {
|
||||||
const request = new XMLHttpRequest();
|
const request = new XMLHttpRequest();
|
||||||
request.open("DELETE", url, true);
|
request.open("DELETE", url, true);
|
||||||
request.onload = () => callback(request);
|
request.onload = () => callback(request);
|
||||||
request.onerror = () => err(request);
|
request.onerror = () => err(request);
|
||||||
request.send();
|
request.send();
|
||||||
};
|
};
|
||||||
|
module.exports = httpDelete
|
||||||
@ -1,7 +1,8 @@
|
|||||||
module.exports = httpGet = (url, callback, err = console.error) => {
|
const httpGet = (url, callback, err = console.error) => {
|
||||||
const request = new XMLHttpRequest();
|
const request = new XMLHttpRequest();
|
||||||
request.open('GET', url, true);
|
request.open('GET', url, true);
|
||||||
request.onload = () => callback(request.responseText);
|
request.onload = () => callback(request.responseText);
|
||||||
request.onerror = () => err(request);
|
request.onerror = () => err(request);
|
||||||
request.send();
|
request.send();
|
||||||
};
|
};
|
||||||
|
module.exports = httpGet
|
||||||
@ -1,8 +1,9 @@
|
|||||||
module.exports = httpPost = (url, callback, data = null, err = console.error) => {
|
const httpPost = (url, data, callback, err = console.error) => {
|
||||||
const request = new XMLHttpRequest();
|
const request = new XMLHttpRequest();
|
||||||
request.open('POST', url, true);
|
request.open('POST', url, true);
|
||||||
request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
|
request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
|
||||||
request.onload = () => callback(request.responseText);
|
request.onload = () => callback(request.responseText);
|
||||||
request.onerror = () => err(request);
|
request.onerror = () => err(request);
|
||||||
request.send(data);
|
request.send(data);
|
||||||
};
|
};
|
||||||
|
module.exports = httpPost
|
||||||
@ -1,8 +1,9 @@
|
|||||||
module.exports = httpPut = (url, data, callback, err = console.error) => {
|
const httpPut = (url, data, callback, err = console.error) => {
|
||||||
const request = new XMLHttpRequest();
|
const request = new XMLHttpRequest();
|
||||||
request.open("PUT", url, true);
|
request.open("PUT", url, true);
|
||||||
request.setRequestHeader('Content-type','application/json; charset=utf-8');
|
request.setRequestHeader('Content-type','application/json; charset=utf-8');
|
||||||
request.onload = () => callback(request);
|
request.onload = () => callback(request);
|
||||||
request.onerror = () => err(request);
|
request.onerror = () => err(request);
|
||||||
request.send(data);
|
request.send(data);
|
||||||
};
|
};
|
||||||
|
module.exports = httpPut
|
||||||
@ -1,3 +1,4 @@
|
|||||||
module.exports = httpsRedirect = () => {
|
const httpsRedirect = () => {
|
||||||
if (location.protocol !== 'https:') location.replace('https://' + location.href.split('//')[1]);
|
if (location.protocol !== 'https:') location.replace('https://' + location.href.split('//')[1]);
|
||||||
};
|
};
|
||||||
|
module.exports = httpsRedirect
|
||||||
@ -1,4 +1,5 @@
|
|||||||
module.exports = inRange = (n, start, end = null) => {
|
const inRange = (n, start, end = null) => {
|
||||||
if (end && start > end) end = [start, (start = end)][0];
|
if (end && start > end) end = [start, (start = end)][0];
|
||||||
return end == null ? n >= 0 && n < start : n >= start && n < end;
|
return end == null ? n >= 0 && n < start : n >= start && n < end;
|
||||||
};
|
};
|
||||||
|
module.exports = inRange
|
||||||
@ -1,5 +1,6 @@
|
|||||||
module.exports = indexOfAll = (arr, val) => {
|
const indexOfAll = (arr, val) => {
|
||||||
const indices = [];
|
const indices = [];
|
||||||
arr.forEach((el, i) => el === val && indices.push(i));
|
arr.forEach((el, i) => el === val && indices.push(i));
|
||||||
return indices;
|
return indices;
|
||||||
};
|
};
|
||||||
|
module.exports = indexOfAll
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = initial = arr => arr.slice(0, -1);
|
const initial = arr => arr.slice(0, -1);
|
||||||
|
module.exports = initial
|
||||||
@ -1,2 +1,3 @@
|
|||||||
module.exports = initialize2DArray = (w, h, val = null) =>
|
const initialize2DArray = (w, h, val = null) =>
|
||||||
Array.from({ length: h }).map(() => Array.from({ length: w }).fill(val));
|
Array.from({ length: h }).map(() => Array.from({ length: w }).fill(val));
|
||||||
|
module.exports = initialize2DArray
|
||||||
@ -1,2 +1,3 @@
|
|||||||
module.exports = initializeArrayWithRange = (end, start = 0, step = 1) =>
|
const initializeArrayWithRange = (end, start = 0, step = 1) =>
|
||||||
Array.from({ length: Math.ceil((end + 1 - start) / step) }).map((v, i) => i * step + start);
|
Array.from({ length: Math.ceil((end + 1 - start) / step) }).map((v, i) => i * step + start);
|
||||||
|
module.exports = initializeArrayWithRange
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
const initializeArrayWithRangeRight = (end, start = 0, step = 1) =>
|
||||||
|
Array.from({ length: Math.ceil((end + 1 - start) / step) }).map(
|
||||||
|
(v, i, arr) => (arr.length - i - 1) * step + start
|
||||||
|
);
|
||||||
|
module.exports = initializeArrayWithRangeRight
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const initializeArrayWithRangeRight = require('./initializeArrayWithRangeRight.js');
|
||||||
|
|
||||||
|
test('Testing initializeArrayWithRangeRight', (t) => {
|
||||||
|
//For more information on all the methods supported by tape
|
||||||
|
//Please go to https://github.com/substack/tape
|
||||||
|
t.true(typeof initializeArrayWithRangeRight === 'function', 'initializeArrayWithRangeRight is a Function');
|
||||||
|
//t.deepEqual(initializeArrayWithRangeRight(args..), 'Expected');
|
||||||
|
//t.equal(initializeArrayWithRangeRight(args..), 'Expected');
|
||||||
|
//t.false(initializeArrayWithRangeRight(args..), 'Expected');
|
||||||
|
//t.throws(initializeArrayWithRangeRight(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = initializeArrayWithValues = (n, val = 0) => Array(n).fill(val);
|
const initializeArrayWithValues = (n, val = 0) => Array(n).fill(val);
|
||||||
|
module.exports = initializeArrayWithValues
|
||||||
@ -1,4 +1,5 @@
|
|||||||
module.exports = intersection = (a, b) => {
|
const intersection = (a, b) => {
|
||||||
const s = new Set(b);
|
const s = new Set(b);
|
||||||
return a.filter(x => s.has(x));
|
return a.filter(x => s.has(x));
|
||||||
};
|
};
|
||||||
|
module.exports = intersection
|
||||||
@ -1,5 +1,6 @@
|
|||||||
module.exports = invertKeyValues = obj =>
|
const invertKeyValues = obj =>
|
||||||
Object.keys(obj).reduce((acc, key) => {
|
Object.keys(obj).reduce((acc, key) => {
|
||||||
acc[obj[key]] = key;
|
acc[obj[key]] = key;
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
module.exports = invertKeyValues
|
||||||
@ -1 +1,2 @@
|
|||||||
module.exports = isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);
|
const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);
|
||||||
|
module.exports = isAbsoluteURL
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user