ran npm run tdd & generated TDD

This commit is contained in:
King
2018-01-09 06:09:49 -05:00
parent e13cee0b45
commit 036b4ae842
386 changed files with 3275 additions and 0 deletions

View File

@ -0,0 +1,4 @@
module.exports = arr => {
const dt = new Date(parseInt(arr.toString().substr(6)));
return `${dt.getDate()}/${dt.getMonth() + 1}/${dt.getFullYear()}`;
};

View File

@ -0,0 +1,13 @@
const test = require('tape');
const JSONToDate = require('./JSONToDate.js');
test('Testing JSONToDate', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof JSONToDate === 'function', 'JSONToDate is a Function');
//t.deepEqual(JSONToDate(args..), 'Expected');
//t.equal(JSONToDate(args..), 'Expected');
//t.false(JSONToDate(args..), 'Expected');
//t.throws(JSONToDate(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');

View File

@ -0,0 +1,13 @@
const test = require('tape');
const RGBToHex = require('./RGBToHex.js');
test('Testing RGBToHex', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof RGBToHex === 'function', 'RGBToHex is a Function');
//t.deepEqual(RGBToHex(args..), 'Expected');
//t.equal(RGBToHex(args..), 'Expected');
//t.false(RGBToHex(args..), 'Expected');
//t.throws(RGBToHex(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,4 @@
module.exports = () =>
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
);

View File

@ -0,0 +1,13 @@
const test = require('tape');
const UUIDGeneratorBrowser = require('./UUIDGeneratorBrowser.js');
test('Testing UUIDGeneratorBrowser', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof UUIDGeneratorBrowser === 'function', 'UUIDGeneratorBrowser is a Function');
//t.deepEqual(UUIDGeneratorBrowser(args..), 'Expected');
//t.equal(UUIDGeneratorBrowser(args..), 'Expected');
//t.false(UUIDGeneratorBrowser(args..), 'Expected');
//t.throws(UUIDGeneratorBrowser(args..), 'Expected');
t.end();
});

10
test/anagrams/anagrams.js Normal file
View File

@ -0,0 +1,10 @@
module.exports = str => {
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
return str
.split('')
.reduce(
(acc, letter, i) =>
acc.concat(anagrams(str.slice(0, i) + str.slice(i + 1)).map(val => letter + val)),
[]
);
};

View File

@ -0,0 +1,13 @@
const test = require('tape');
const anagrams = require('./anagrams.js');
test('Testing anagrams', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof anagrams === 'function', 'anagrams is a Function');
//t.deepEqual(anagrams(args..), 'Expected');
//t.equal(anagrams(args..), 'Expected');
//t.false(anagrams(args..), 'Expected');
//t.throws(anagrams(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,2 @@
module.exports = (arr, listID) =>
arr.map(item => (document.querySelector('#' + listID).innerHTML += `<li>${item}</li>`));

View File

@ -0,0 +1,13 @@
const test = require('tape');
const arrayToHtmlList = require('./arrayToHtmlList.js');
test('Testing arrayToHtmlList', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof arrayToHtmlList === 'function', 'arrayToHtmlList is a Function');
//t.deepEqual(arrayToHtmlList(args..), 'Expected');
//t.equal(arrayToHtmlList(args..), 'Expected');
//t.false(arrayToHtmlList(args..), 'Expected');
//t.throws(arrayToHtmlList(args..), 'Expected');
t.end();
});

1
test/average/average.js Normal file
View File

@ -0,0 +1 @@
module.exports = (...nums) => [...nums].reduce((acc, val) => acc + val, 0) / nums.length;

View File

@ -0,0 +1,13 @@
const test = require('tape');
const average = require('./average.js');
test('Testing average', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof average === 'function', 'average is a Function');
//t.deepEqual(average(args..), 'Expected');
//t.equal(average(args..), 'Expected');
//t.false(average(args..), 'Expected');
//t.throws(average(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,7 @@
module.exports = (arr, val, start = 0, end = arr.length - 1) => {
if (start > end) return -1;
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, mid + 1, end);
return mid;
}

View File

@ -0,0 +1,13 @@
const test = require('tape');
const binarySearch = require('./binarySearch.js');
test('Testing binarySearch', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof binarySearch === 'function', 'binarySearch is a Function');
//t.deepEqual(binarySearch(args..), 'Expected');
//t.equal(binarySearch(args..), 'Expected');
//t.false(binarySearch(args..), 'Expected');
//t.throws(binarySearch(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,3 @@
module.exports = () =>
document.documentElement.clientHeight + window.scrollY >=
(document.documentElement.scrollHeight || document.documentElement.clientHeight);

View File

@ -0,0 +1,13 @@
const test = require('tape');
const bottomVisible = require('./bottomVisible.js');
test('Testing bottomVisible', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof bottomVisible === 'function', 'bottomVisible is a Function');
//t.deepEqual(bottomVisible(args..), 'Expected');
//t.equal(bottomVisible(args..), 'Expected');
//t.false(bottomVisible(args..), 'Expected');
//t.throws(bottomVisible(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = str => new Blob([str]).size;

View File

@ -0,0 +1,13 @@
const test = require('tape');
const byteSize = require('./byteSize.js');
test('Testing byteSize', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof byteSize === 'function', 'byteSize is a Function');
//t.deepEqual(byteSize(args..), 'Expected');
//t.equal(byteSize(args..), 'Expected');
//t.false(byteSize(args..), 'Expected');
//t.throws(byteSize(args..), 'Expected');
t.end();
});

1
test/call/call.js Normal file
View File

@ -0,0 +1 @@
module.exports = (key, ...args) => context => context[key](...args);

13
test/call/call.test.js Normal file
View File

@ -0,0 +1,13 @@
const test = require('tape');
const call = require('./call.js');
test('Testing call', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof call === 'function', 'call is a Function');
//t.deepEqual(call(args..), 'Expected');
//t.equal(call(args..), 'Expected');
//t.false(call(args..), 'Expected');
//t.throws(call(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,2 @@
module.exports = ([first, ...rest], lowerRest = false) =>
first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join(''));

View File

@ -0,0 +1,13 @@
const test = require('tape');
const capitalize = require('./capitalize.js');
test('Testing capitalize', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof capitalize === 'function', 'capitalize is a Function');
//t.deepEqual(capitalize(args..), 'Expected');
//t.equal(capitalize(args..), 'Expected');
//t.false(capitalize(args..), 'Expected');
//t.throws(capitalize(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = str => str.replace(/\b[a-z]/g, char => char.toUpperCase());

View File

@ -0,0 +1,13 @@
const test = require('tape');
const capitalizeEveryWord = require('./capitalizeEveryWord.js');
test('Testing capitalizeEveryWord', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof capitalizeEveryWord === 'function', 'capitalizeEveryWord is a Function');
//t.deepEqual(capitalizeEveryWord(args..), 'Expected');
//t.equal(capitalizeEveryWord(args..), 'Expected');
//t.false(capitalizeEveryWord(args..), 'Expected');
//t.throws(capitalizeEveryWord(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,5 @@
module.exports = fns => {
let curr = 0;
const next = () => fns[curr++](next);
next();
};

View File

@ -0,0 +1,13 @@
const test = require('tape');
const chainAsync = require('./chainAsync.js');
test('Testing chainAsync', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof chainAsync === 'function', 'chainAsync is a Function');
//t.deepEqual(chainAsync(args..), 'Expected');
//t.equal(chainAsync(args..), 'Expected');
//t.false(chainAsync(args..), 'Expected');
//t.throws(chainAsync(args..), 'Expected');
t.end();
});

4
test/chunk/chunk.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = (arr, size) =>
Array.from({ length: Math.ceil(arr.length / size) }, (v, i) =>
arr.slice(i * size, i * size + size)
);

13
test/chunk/chunk.test.js Normal file
View File

@ -0,0 +1,13 @@
const test = require('tape');
const chunk = require('./chunk.js');
test('Testing chunk', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof chunk === 'function', 'chunk is a Function');
//t.deepEqual(chunk(args..), 'Expected');
//t.equal(chunk(args..), 'Expected');
//t.false(chunk(args..), 'Expected');
//t.throws(chunk(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));

View File

@ -0,0 +1,13 @@
const test = require('tape');
const clampNumber = require('./clampNumber.js');
test('Testing clampNumber', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof clampNumber === 'function', 'clampNumber is a Function');
//t.deepEqual(clampNumber(args..), 'Expected');
//t.equal(clampNumber(args..), 'Expected');
//t.false(clampNumber(args..), 'Expected');
//t.throws(clampNumber(args..), 'Expected');
t.end();
});

10
test/cleanObj/cleanObj.js Normal file
View File

@ -0,0 +1,10 @@
module.exports = (obj, keysToKeep = [], childIndicator) => {
Object.keys(obj).forEach(key => {
if (key === childIndicator) {
cleanObj(obj[key], keysToKeep, childIndicator);
} else if (!keysToKeep.includes(key)) {
delete obj[key];
}
});
return obj;
};

View File

@ -0,0 +1,13 @@
const test = require('tape');
const cleanObj = require('./cleanObj.js');
test('Testing cleanObj', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof cleanObj === 'function', 'cleanObj is a Function');
//t.deepEqual(cleanObj(args..), 'Expected');
//t.equal(cleanObj(args..), 'Expected');
//t.false(cleanObj(args..), 'Expected');
//t.throws(cleanObj(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = regExp => new RegExp(regExp.source, regExp.flags);

View File

@ -0,0 +1,13 @@
const test = require('tape');
const cloneRegExp = require('./cloneRegExp.js');
test('Testing cloneRegExp', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof cloneRegExp === 'function', 'cloneRegExp is a Function');
//t.deepEqual(cloneRegExp(args..), 'Expected');
//t.equal(cloneRegExp(args..), 'Expected');
//t.false(cloneRegExp(args..), 'Expected');
//t.throws(cloneRegExp(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = (...args) => args.find(_ => ![undefined, null].includes(_));

View File

@ -0,0 +1,13 @@
const test = require('tape');
const coalesce = require('./coalesce.js');
test('Testing coalesce', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof coalesce === 'function', 'coalesce is a Function');
//t.deepEqual(coalesce(args..), 'Expected');
//t.equal(coalesce(args..), 'Expected');
//t.false(coalesce(args..), 'Expected');
//t.throws(coalesce(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = valid => (...args) => args.find(valid);

View File

@ -0,0 +1,13 @@
const test = require('tape');
const coalesceFactory = require('./coalesceFactory.js');
test('Testing coalesceFactory', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof coalesceFactory === 'function', 'coalesceFactory is a Function');
//t.deepEqual(coalesceFactory(args..), 'Expected');
//t.equal(coalesceFactory(args..), 'Expected');
//t.false(coalesceFactory(args..), 'Expected');
//t.throws(coalesceFactory(args..), 'Expected');
t.end();
});

1
test/collatz/collatz.js Normal file
View File

@ -0,0 +1 @@
module.exports = n => (n % 2 == 0 ? n / 2 : 3 * n + 1);

View File

@ -0,0 +1,13 @@
const test = require('tape');
const collatz = require('./collatz.js');
test('Testing collatz', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof collatz === 'function', 'collatz is a Function');
//t.deepEqual(collatz(args..), 'Expected');
//t.equal(collatz(args..), 'Expected');
//t.false(collatz(args..), 'Expected');
//t.throws(collatz(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = fn => (...args) => fn(args);

View File

@ -0,0 +1,13 @@
const test = require('tape');
const collectInto = require('./collectInto.js');
test('Testing collectInto', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof collectInto === 'function', 'collectInto is a Function');
//t.deepEqual(collectInto(args..), 'Expected');
//t.equal(collectInto(args..), 'Expected');
//t.false(collectInto(args..), 'Expected');
//t.throws(collectInto(args..), 'Expected');
t.end();
});

1
test/compact/compact.js Normal file
View File

@ -0,0 +1 @@
module.exports = arr => arr.filter(Boolean);

View File

@ -0,0 +1,13 @@
const test = require('tape');
const compact = require('./compact.js');
test('Testing compact', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof compact === 'function', 'compact is a Function');
//t.deepEqual(compact(args..), 'Expected');
//t.equal(compact(args..), 'Expected');
//t.false(compact(args..), 'Expected');
//t.throws(compact(args..), 'Expected');
t.end();
});

1
test/compose/compose.js Normal file
View File

@ -0,0 +1 @@
module.exports = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));

View File

@ -0,0 +1,13 @@
const test = require('tape');
const compose = require('./compose.js');
test('Testing compose', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof compose === 'function', 'compose is a Function');
//t.deepEqual(compose(args..), 'Expected');
//t.equal(compose(args..), 'Expected');
//t.false(compose(args..), 'Expected');
//t.throws(compose(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,17 @@
module.exports = str => {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
const selected =
document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
el.select();
document.execCommand('copy');
document.body.removeChild(el);
if (selected) {
document.getSelection().removeAllRanges();
document.getSelection().addRange(selected);
}
};

View File

@ -0,0 +1,13 @@
const test = require('tape');
const copyToClipboard = require('./copyToClipboard.js');
test('Testing copyToClipboard', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof copyToClipboard === 'function', 'copyToClipboard is a Function');
//t.deepEqual(copyToClipboard(args..), 'Expected');
//t.equal(copyToClipboard(args..), 'Expected');
//t.false(copyToClipboard(args..), 'Expected');
//t.throws(copyToClipboard(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a + 0), 0);

View File

@ -0,0 +1,13 @@
const test = require('tape');
const countOccurrences = require('./countOccurrences.js');
test('Testing countOccurrences', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof countOccurrences === 'function', 'countOccurrences is a Function');
//t.deepEqual(countOccurrences(args..), 'Expected');
//t.equal(countOccurrences(args..), 'Expected');
//t.false(countOccurrences(args..), 'Expected');
//t.throws(countOccurrences(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = str => (str.match(/[aeiou]/gi) || []).length;

View File

@ -0,0 +1,13 @@
const test = require('tape');
const countVowels = require('./countVowels.js');
test('Testing countVowels', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof countVowels === 'function', 'countVowels is a Function');
//t.deepEqual(countVowels(args..), 'Expected');
//t.equal(countVowels(args..), 'Expected');
//t.false(countVowels(args..), 'Expected');
//t.throws(countVowels(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,5 @@
module.exports = str => {
const el = document.createElement('div');
el.innerHTML = str;
return el.firstElementChild;
};

View File

@ -0,0 +1,13 @@
const test = require('tape');
const createElement = require('./createElement.js');
test('Testing createElement', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof createElement === 'function', 'createElement is a Function');
//t.deepEqual(createElement(args..), 'Expected');
//t.equal(createElement(args..), 'Expected');
//t.false(createElement(args..), 'Expected');
//t.throws(createElement(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = () => window.location.href;

View File

@ -0,0 +1,13 @@
const test = require('tape');
const currentURL = require('./currentURL.js');
test('Testing currentURL', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof currentURL === 'function', 'currentURL is a Function');
//t.deepEqual(currentURL(args..), 'Expected');
//t.equal(currentURL(args..), 'Expected');
//t.false(currentURL(args..), 'Expected');
//t.throws(currentURL(args..), 'Expected');
t.end();
});

2
test/curry/curry.js Normal file
View File

@ -0,0 +1,2 @@
module.exports = (fn, arity = fn.length, ...args) =>
arity <= args.length ? fn(...args) : curry.bind(null, fn, arity, ...args);

13
test/curry/curry.test.js Normal file
View File

@ -0,0 +1,13 @@
const test = require('tape');
const curry = require('./curry.js');
test('Testing curry', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof curry === 'function', 'curry is a Function');
//t.deepEqual(curry(args..), 'Expected');
//t.equal(curry(args..), 'Expected');
//t.false(curry(args..), 'Expected');
//t.throws(curry(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));

View File

@ -0,0 +1,13 @@
const test = require('tape');
const deepFlatten = require('./deepFlatten.js');
test('Testing deepFlatten', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof deepFlatten === 'function', 'deepFlatten is a Function');
//t.deepEqual(deepFlatten(args..), 'Expected');
//t.equal(deepFlatten(args..), 'Expected');
//t.false(deepFlatten(args..), 'Expected');
//t.throws(deepFlatten(args..), 'Expected');
t.end();
});

1
test/defer/defer.js Normal file
View File

@ -0,0 +1 @@
module.exports = (fn, ...args) => setTimeout(fn, 1, ...args);

13
test/defer/defer.test.js Normal file
View File

@ -0,0 +1,13 @@
const test = require('tape');
const defer = require('./defer.js');
test('Testing defer', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof defer === 'function', 'defer is a Function');
//t.deepEqual(defer(args..), 'Expected');
//t.equal(defer(args..), 'Expected');
//t.false(defer(args..), 'Expected');
//t.throws(defer(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,4 @@
module.exports = () =>
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
? 'Mobile'
: 'Desktop';

View File

@ -0,0 +1,13 @@
const test = require('tape');
const detectDeviceType = require('./detectDeviceType.js');
test('Testing detectDeviceType', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof detectDeviceType === 'function', 'detectDeviceType is a Function');
//t.deepEqual(detectDeviceType(args..), 'Expected');
//t.equal(detectDeviceType(args..), 'Expected');
//t.false(detectDeviceType(args..), 'Expected');
//t.throws(detectDeviceType(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,4 @@
module.exports = (a, b) => {
const s = new Set(b);
return a.filter(x => !s.has(x));
};

View File

@ -0,0 +1,13 @@
const test = require('tape');
const difference = require('./difference.js');
test('Testing difference', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof difference === 'function', 'difference is a Function');
//t.deepEqual(difference(args..), 'Expected');
//t.equal(difference(args..), 'Expected');
//t.false(difference(args..), 'Expected');
//t.throws(difference(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = (arr, val, comp) => arr.filter(a => val.findIndex(b => comp(a, b)) === -1);

View File

@ -0,0 +1,13 @@
const test = require('tape');
const differenceWith = require('./differenceWith.js');
test('Testing differenceWith', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof differenceWith === 'function', 'differenceWith is a Function');
//t.deepEqual(differenceWith(args..), 'Expected');
//t.equal(differenceWith(args..), 'Expected');
//t.false(differenceWith(args..), 'Expected');
//t.throws(differenceWith(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = n => [...`${n}`].map(i => parseInt(i));

View File

@ -0,0 +1,13 @@
const test = require('tape');
const digitize = require('./digitize.js');
test('Testing digitize', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof digitize === 'function', 'digitize is a Function');
//t.deepEqual(digitize(args..), 'Expected');
//t.equal(digitize(args..), 'Expected');
//t.false(digitize(args..), 'Expected');
//t.throws(digitize(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);

View File

@ -0,0 +1,13 @@
const test = require('tape');
const distance = require('./distance.js');
test('Testing distance', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof distance === 'function', 'distance is a Function');
//t.deepEqual(distance(args..), 'Expected');
//t.equal(distance(args..), 'Expected');
//t.false(distance(args..), 'Expected');
//t.throws(distance(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = arr => [...new Set(arr)];

View File

@ -0,0 +1,13 @@
const test = require('tape');
const distinctValuesOfArray = require('./distinctValuesOfArray.js');
test('Testing distinctValuesOfArray', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof distinctValuesOfArray === 'function', 'distinctValuesOfArray is a Function');
//t.deepEqual(distinctValuesOfArray(args..), 'Expected');
//t.equal(distinctValuesOfArray(args..), 'Expected');
//t.false(distinctValuesOfArray(args..), 'Expected');
//t.throws(distinctValuesOfArray(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,4 @@
module.exports = (arr, func) => {
while (arr.length > 0 && !func(arr[0])) arr = arr.slice(1);
return arr;
};

View File

@ -0,0 +1,13 @@
const test = require('tape');
const dropElements = require('./dropElements.js');
test('Testing dropElements', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof dropElements === 'function', 'dropElements is a Function');
//t.deepEqual(dropElements(args..), 'Expected');
//t.equal(dropElements(args..), 'Expected');
//t.false(dropElements(args..), 'Expected');
//t.throws(dropElements(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = (arr, n = 1) => arr.slice(0, -n);

View File

@ -0,0 +1,13 @@
const test = require('tape');
const dropRight = require('./dropRight.js');
test('Testing dropRight', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof dropRight === 'function', 'dropRight is a Function');
//t.deepEqual(dropRight(args..), 'Expected');
//t.equal(dropRight(args..), 'Expected');
//t.false(dropRight(args..), 'Expected');
//t.throws(dropRight(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,8 @@
module.exports = (el, partiallyVisible = false) => {
const { top, left, bottom, right } = el.getBoundingClientRect();
const { innerHeight, innerWidth } = window;
return partiallyVisible
? ((top > 0 && top < innerHeight) || (bottom > 0 && bottom < innerHeight)) &&
((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth))
: top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
};

View File

@ -0,0 +1,13 @@
const test = require('tape');
const elementIsVisibleInViewport = require('./elementIsVisibleInViewport.js');
test('Testing elementIsVisibleInViewport', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof elementIsVisibleInViewport === 'function', 'elementIsVisibleInViewport is a Function');
//t.deepEqual(elementIsVisibleInViewport(args..), 'Expected');
//t.equal(elementIsVisibleInViewport(args..), 'Expected');
//t.false(elementIsVisibleInViewport(args..), 'Expected');
//t.throws(elementIsVisibleInViewport(args..), 'Expected');
t.end();
});

18
test/elo/elo.js Normal file
View File

@ -0,0 +1,18 @@
module.exports = ([...ratings], kFactor = 32, selfRating) => {
const [a, b] = ratings;
const expectedScore = (self, opponent) => 1 / (1 + 10 ** ((opponent - self) / 400));
const newRating = (rating, i) =>
(selfRating || rating) + kFactor * (i - expectedScore(i ? a : b, i ? b : a));
if (ratings.length === 2) {
return [newRating(a, 1), newRating(b, 0)];
} else {
for (let i = 0; i < ratings.length; i++) {
let j = i;
while (j < ratings.length - 1) {
[ratings[i], ratings[j + 1]] = elo([ratings[i], ratings[j + 1]], kFactor);
j++;
}
}
}
return ratings;
};

13
test/elo/elo.test.js Normal file
View File

@ -0,0 +1,13 @@
const test = require('tape');
const elo = require('./elo.js');
test('Testing elo', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof elo === 'function', 'elo is a Function');
//t.deepEqual(elo(args..), 'Expected');
//t.equal(elo(args..), 'Expected');
//t.false(elo(args..), 'Expected');
//t.throws(elo(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,12 @@
module.exports = str =>
str.replace(
/[&<>'"]/g,
tag =>
({
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
"'": '&#39;',
'"': '&quot;'
}[tag] || tag)
);

View File

@ -0,0 +1,13 @@
const test = require('tape');
const escapeHTML = require('./escapeHTML.js');
test('Testing escapeHTML', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof escapeHTML === 'function', 'escapeHTML is a Function');
//t.deepEqual(escapeHTML(args..), 'Expected');
//t.equal(escapeHTML(args..), 'Expected');
//t.false(escapeHTML(args..), 'Expected');
//t.throws(escapeHTML(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

View File

@ -0,0 +1,13 @@
const test = require('tape');
const escapeRegExp = require('./escapeRegExp.js');
test('Testing escapeRegExp', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof escapeRegExp === 'function', 'escapeRegExp is a Function');
//t.deepEqual(escapeRegExp(args..), 'Expected');
//t.equal(escapeRegExp(args..), 'Expected');
//t.false(escapeRegExp(args..), 'Expected');
//t.throws(escapeRegExp(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1 @@
module.exports = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1);

View File

@ -0,0 +1,13 @@
const test = require('tape');
const everyNth = require('./everyNth.js');
test('Testing everyNth', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof everyNth === 'function', 'everyNth is a Function');
//t.deepEqual(everyNth(args..), 'Expected');
//t.equal(everyNth(args..), 'Expected');
//t.false(everyNth(args..), 'Expected');
//t.throws(everyNth(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,7 @@
module.exports = shortHex =>
'#' +
shortHex
.slice(shortHex.startsWith('#') ? 1 : 0)
.split('')
.map(x => x + x)
.join('');

View File

@ -0,0 +1,13 @@
const test = require('tape');
const extendHex = require('./extendHex.js');
test('Testing extendHex', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof extendHex === 'function', 'extendHex is a Function');
//t.deepEqual(extendHex(args..), 'Expected');
//t.equal(extendHex(args..), 'Expected');
//t.false(extendHex(args..), 'Expected');
//t.throws(extendHex(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,6 @@
module.exports = n =>
n < 0
? (() => {
throw new TypeError('Negative numbers are not allowed!');
})()
: n <= 1 ? 1 : n * factorial(n - 1);

View File

@ -0,0 +1,13 @@
const test = require('tape');
const factorial = require('./factorial.js');
test('Testing factorial', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof factorial === 'function', 'factorial is a Function');
//t.deepEqual(factorial(args..), 'Expected');
//t.equal(factorial(args..), 'Expected');
//t.false(factorial(args..), 'Expected');
//t.throws(factorial(args..), 'Expected');
t.end();
});

19
test/factors/factors.js Normal file
View File

@ -0,0 +1,19 @@
module.exports = (num, primes = false) => {
const isPrime = num => {
const boundary = Math.floor(Math.sqrt(num));
for (var i = 2; i <= boundary; i++) if (num % i === 0) return false;
return num >= 2;
};
const isNeg = num < 0;
num = isNeg ? -num : num;
let array = Array.from({ length: num - 1 })
.map((val, i) => (num % (i + 2) === 0 ? i + 2 : false))
.filter(val => val);
if (isNeg)
array = array.reduce((acc, val) => {
acc.push(val);
acc.push(-val);
return acc;
}, []);
return primes ? array.filter(isPrime) : array;
};

View File

@ -0,0 +1,13 @@
const test = require('tape');
const factors = require('./factors.js');
test('Testing factors', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof factors === 'function', 'factors is a Function');
//t.deepEqual(factors(args..), 'Expected');
//t.equal(factors(args..), 'Expected');
//t.false(factors(args..), 'Expected');
//t.throws(factors(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,5 @@
module.exports = n =>
Array.from({ length: n }).reduce(
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
[]
);

View File

@ -0,0 +1,13 @@
const test = require('tape');
const fibonacci = require('./fibonacci.js');
test('Testing fibonacci', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof fibonacci === 'function', 'fibonacci is a Function');
//t.deepEqual(fibonacci(args..), 'Expected');
//t.equal(fibonacci(args..), 'Expected');
//t.false(fibonacci(args..), 'Expected');
//t.throws(fibonacci(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,2 @@
module.exports = num =>
Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));

View File

@ -0,0 +1,13 @@
const test = require('tape');
const fibonacciCountUntilNum = require('./fibonacciCountUntilNum.js');
test('Testing fibonacciCountUntilNum', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof fibonacciCountUntilNum === 'function', 'fibonacciCountUntilNum is a Function');
//t.deepEqual(fibonacciCountUntilNum(args..), 'Expected');
//t.equal(fibonacciCountUntilNum(args..), 'Expected');
//t.false(fibonacciCountUntilNum(args..), 'Expected');
//t.throws(fibonacciCountUntilNum(args..), 'Expected');
t.end();
});

View File

@ -0,0 +1,7 @@
module.exports = num => {
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(
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
[]
);
};

View File

@ -0,0 +1,13 @@
const test = require('tape');
const fibonacciUntilNum = require('./fibonacciUntilNum.js');
test('Testing fibonacciUntilNum', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof fibonacciUntilNum === 'function', 'fibonacciUntilNum is a Function');
//t.deepEqual(fibonacciUntilNum(args..), 'Expected');
//t.equal(fibonacciUntilNum(args..), 'Expected');
//t.false(fibonacciUntilNum(args..), 'Expected');
//t.throws(fibonacciUntilNum(args..), 'Expected');
t.end();
});

Some files were not shown because too many files have changed in this diff Show More