Migrated tests to jest
Used jest-codemods to migrate, will have to pass everything by hand before we can merge.
This commit is contained in:
10
test6/URLJoin/URLJoin.js
Normal file
10
test6/URLJoin/URLJoin.js
Normal file
@ -0,0 +1,10 @@
|
||||
const URLJoin = (...args) =>
|
||||
args
|
||||
.join('/')
|
||||
.replace(/[\/]+/g, '/')
|
||||
.replace(/^(.+):\//, '$1://')
|
||||
.replace(/^file:/, 'file:/')
|
||||
.replace(/\/(\?|&|#[^!])/g, '$1')
|
||||
.replace(/\?/g, '&')
|
||||
.replace('&', '?');
|
||||
module.exports = URLJoin;
|
||||
10
test6/URLJoin/URLJoin.test.js
Normal file
10
test6/URLJoin/URLJoin.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const URLJoin = require('./URLJoin.js');
|
||||
|
||||
test('Testing URLJoin', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof URLJoin === 'function').toBeTruthy();
|
||||
expect(URLJoin('http://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo')).toBe('http://www.google.com/a/b/cd?foo=123&bar=foo');
|
||||
expect(URLJoin('file://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo')).toBe('file:///www.google.com/a/b/cd?foo=123&bar=foo');
|
||||
});
|
||||
5
test6/UUIDGeneratorBrowser/UUIDGeneratorBrowser.js
Normal file
5
test6/UUIDGeneratorBrowser/UUIDGeneratorBrowser.js
Normal file
@ -0,0 +1,5 @@
|
||||
const UUIDGeneratorBrowser = () =>
|
||||
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
||||
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
|
||||
);
|
||||
module.exports = UUIDGeneratorBrowser;
|
||||
8
test6/UUIDGeneratorBrowser/UUIDGeneratorBrowser.test.js
Normal file
8
test6/UUIDGeneratorBrowser/UUIDGeneratorBrowser.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const UUIDGeneratorBrowser = require('./UUIDGeneratorBrowser.js');
|
||||
|
||||
test('Testing UUIDGeneratorBrowser', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof UUIDGeneratorBrowser === 'function').toBeTruthy();
|
||||
});
|
||||
6
test6/UUIDGeneratorNode/UUIDGeneratorNode.js
Normal file
6
test6/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;
|
||||
11
test6/UUIDGeneratorNode/UUIDGeneratorNode.test.js
Normal file
11
test6/UUIDGeneratorNode/UUIDGeneratorNode.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const UUIDGeneratorNode = require('./UUIDGeneratorNode.js');
|
||||
|
||||
test('Testing UUIDGeneratorNode', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof UUIDGeneratorNode === 'function').toBeTruthy();
|
||||
const uuid = UUIDGeneratorNode();
|
||||
expect([uuid[8], uuid[13], uuid[18], uuid[23]]).toEqual(['-', '-', '-', '-']);
|
||||
expect(/^[0-9A-Fa-f-]+$/.test(uuid)).toBeTruthy();
|
||||
});
|
||||
16
test6/runAsync/runAsync.js
Normal file
16
test6/runAsync/runAsync.js
Normal file
@ -0,0 +1,16 @@
|
||||
const runAsync = fn => {
|
||||
const worker = new Worker(
|
||||
URL.createObjectURL(new Blob([`postMessage((${fn})());`]), {
|
||||
type: 'application/javascript; charset=utf-8'
|
||||
})
|
||||
);
|
||||
return new Promise((res, rej) => {
|
||||
worker.onmessage = ({ data }) => {
|
||||
res(data), worker.terminate();
|
||||
};
|
||||
worker.onerror = err => {
|
||||
rej(err), worker.terminate();
|
||||
};
|
||||
});
|
||||
};
|
||||
module.exports = runAsync;
|
||||
8
test6/runAsync/runAsync.test.js
Normal file
8
test6/runAsync/runAsync.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const runAsync = require('./runAsync.js');
|
||||
|
||||
test('Testing runAsync', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof runAsync === 'function').toBeTruthy();
|
||||
});
|
||||
2
test6/runPromisesInSeries/runPromisesInSeries.js
Normal file
2
test6/runPromisesInSeries/runPromisesInSeries.js
Normal file
@ -0,0 +1,2 @@
|
||||
const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.resolve());
|
||||
module.exports = runPromisesInSeries;
|
||||
10
test6/runPromisesInSeries/runPromisesInSeries.test.js
Normal file
10
test6/runPromisesInSeries/runPromisesInSeries.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const runPromisesInSeries = require('./runPromisesInSeries.js');
|
||||
|
||||
test('Testing runPromisesInSeries', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof runPromisesInSeries === 'function').toBeTruthy();
|
||||
const delay = d => new Promise(r => setTimeout(r, d));
|
||||
runPromisesInSeries([() => delay(100), () => delay(200).then(() => )]);
|
||||
});
|
||||
2
test6/sample/sample.js
Normal file
2
test6/sample/sample.js
Normal file
@ -0,0 +1,2 @@
|
||||
const sample = arr => arr[Math.floor(Math.random() * arr.length)];
|
||||
module.exports = sample;
|
||||
12
test6/sample/sample.test.js
Normal file
12
test6/sample/sample.test.js
Normal file
@ -0,0 +1,12 @@
|
||||
const expect = require('expect');
|
||||
const sample = require('./sample.js');
|
||||
|
||||
test('Testing sample', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof sample === 'function').toBeTruthy();
|
||||
const arr = [3,7,9,11];
|
||||
expect(arr.includes(sample(arr))).toBeTruthy();
|
||||
expect(sample([1])).toBe(1);
|
||||
expect(sample([])).toBe(undefined);
|
||||
});
|
||||
9
test6/sampleSize/sampleSize.js
Normal file
9
test6/sampleSize/sampleSize.js
Normal file
@ -0,0 +1,9 @@
|
||||
const sampleSize = ([...arr], n = 1) => {
|
||||
let m = arr.length;
|
||||
while (m) {
|
||||
const i = Math.floor(Math.random() * m--);
|
||||
[arr[m], arr[i]] = [arr[i], arr[m]];
|
||||
}
|
||||
return arr.slice(0, n);
|
||||
};
|
||||
module.exports = sampleSize;
|
||||
14
test6/sampleSize/sampleSize.test.js
Normal file
14
test6/sampleSize/sampleSize.test.js
Normal file
@ -0,0 +1,14 @@
|
||||
const expect = require('expect');
|
||||
const sampleSize = require('./sampleSize.js');
|
||||
|
||||
test('Testing sampleSize', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof sampleSize === 'function').toBeTruthy();
|
||||
const arr = [3,7,9,11];
|
||||
expect(sampleSize(arr).length).toBe(1);
|
||||
expect(sampleSize(arr, 2).every(x => arr.includes(x))).toBeTruthy();
|
||||
expect(sampleSize(arr, 5).length).toBe(4);
|
||||
expect(sampleSize([], 2)).toEqual([]);
|
||||
expect(sampleSize(arr, 0)).toEqual([]);
|
||||
});
|
||||
8
test6/scrollToTop/scrollToTop.js
Normal file
8
test6/scrollToTop/scrollToTop.js
Normal file
@ -0,0 +1,8 @@
|
||||
const scrollToTop = () => {
|
||||
const c = document.documentElement.scrollTop || document.body.scrollTop;
|
||||
if (c > 0) {
|
||||
window.requestAnimationFrame(scrollToTop);
|
||||
window.scrollTo(0, c - c / 8);
|
||||
}
|
||||
};
|
||||
module.exports = scrollToTop;
|
||||
8
test6/scrollToTop/scrollToTop.test.js
Normal file
8
test6/scrollToTop/scrollToTop.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const scrollToTop = require('./scrollToTop.js');
|
||||
|
||||
test('Testing scrollToTop', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof scrollToTop === 'function').toBeTruthy();
|
||||
});
|
||||
9
test6/sdbm/sdbm.js
Normal file
9
test6/sdbm/sdbm.js
Normal file
@ -0,0 +1,9 @@
|
||||
const sdbm = str => {
|
||||
let arr = str.split('');
|
||||
return arr.reduce(
|
||||
(hashCode, currentVal) =>
|
||||
(hashCode = currentVal.charCodeAt(0) + (hashCode << 6) + (hashCode << 16) - hashCode),
|
||||
0
|
||||
);
|
||||
};
|
||||
module.exports = sdbm;
|
||||
9
test6/sdbm/sdbm.test.js
Normal file
9
test6/sdbm/sdbm.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const sdbm = require('./sdbm.js');
|
||||
|
||||
test('Testing sdbm', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof sdbm === 'function').toBeTruthy();
|
||||
expect(sdbm('name')).toBe(-3521204949);
|
||||
});
|
||||
2
test6/serializeCookie/serializeCookie.js
Normal file
2
test6/serializeCookie/serializeCookie.js
Normal file
@ -0,0 +1,2 @@
|
||||
const serializeCookie = (name, val) => `${encodeURIComponent(name)}=${encodeURIComponent(val)}`;
|
||||
module.exports = serializeCookie;
|
||||
9
test6/serializeCookie/serializeCookie.test.js
Normal file
9
test6/serializeCookie/serializeCookie.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const serializeCookie = require('./serializeCookie.js');
|
||||
|
||||
test('Testing serializeCookie', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof serializeCookie === 'function').toBeTruthy();
|
||||
expect(serializeCookie('foo', 'bar')).toBe('foo=bar');
|
||||
});
|
||||
2
test6/setStyle/setStyle.js
Normal file
2
test6/setStyle/setStyle.js
Normal file
@ -0,0 +1,2 @@
|
||||
const setStyle = (el, ruleName, val) => (el.style[ruleName] = val);
|
||||
module.exports = setStyle;
|
||||
8
test6/setStyle/setStyle.test.js
Normal file
8
test6/setStyle/setStyle.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const setStyle = require('./setStyle.js');
|
||||
|
||||
test('Testing setStyle', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof setStyle === 'function').toBeTruthy();
|
||||
});
|
||||
2
test6/shallowClone/shallowClone.js
Normal file
2
test6/shallowClone/shallowClone.js
Normal file
@ -0,0 +1,2 @@
|
||||
const shallowClone = obj => Object.assign({}, obj);
|
||||
module.exports = shallowClone;
|
||||
12
test6/shallowClone/shallowClone.test.js
Normal file
12
test6/shallowClone/shallowClone.test.js
Normal file
@ -0,0 +1,12 @@
|
||||
const expect = require('expect');
|
||||
const shallowClone = require('./shallowClone.js');
|
||||
|
||||
test('Testing shallowClone', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof shallowClone === 'function').toBeTruthy();
|
||||
const a = { foo: 'bar', obj: { a: 1, b: 2 } };
|
||||
const b = shallowClone(a);
|
||||
expect(a).not.toBe(b);
|
||||
expect(a.obj).toBe(b.obj);
|
||||
});
|
||||
2
test6/show/show.js
Normal file
2
test6/show/show.js
Normal file
@ -0,0 +1,2 @@
|
||||
const show = (...el) => [...el].forEach(e => (e.style.display = ''));
|
||||
module.exports = show;
|
||||
8
test6/show/show.test.js
Normal file
8
test6/show/show.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const show = require('./show.js');
|
||||
|
||||
test('Testing show', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof show === 'function').toBeTruthy();
|
||||
});
|
||||
9
test6/shuffle/shuffle.js
Normal file
9
test6/shuffle/shuffle.js
Normal file
@ -0,0 +1,9 @@
|
||||
const shuffle = ([...arr]) => {
|
||||
let m = arr.length;
|
||||
while (m) {
|
||||
const i = Math.floor(Math.random() * m--);
|
||||
[arr[m], arr[i]] = [arr[i], arr[m]];
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
module.exports = shuffle;
|
||||
13
test6/shuffle/shuffle.test.js
Normal file
13
test6/shuffle/shuffle.test.js
Normal file
@ -0,0 +1,13 @@
|
||||
const expect = require('expect');
|
||||
const shuffle = require('./shuffle.js');
|
||||
|
||||
test('Testing shuffle', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof shuffle === 'function').toBeTruthy();
|
||||
const arr = [1,2,3,4,5,6];
|
||||
expect(shuffle(arr)).not.toBe(arr);
|
||||
expect(shuffle(arr).every(x => arr.includes(x))).toBeTruthy();
|
||||
expect(shuffle([])).toEqual([]);
|
||||
expect(shuffle([1])).toEqual([1]);
|
||||
});
|
||||
2
test6/similarity/similarity.js
Normal file
2
test6/similarity/similarity.js
Normal file
@ -0,0 +1,2 @@
|
||||
const similarity = (arr, values) => arr.filter(v => values.includes(v));
|
||||
module.exports = similarity;
|
||||
9
test6/similarity/similarity.test.js
Normal file
9
test6/similarity/similarity.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const similarity = require('./similarity.js');
|
||||
|
||||
test('Testing similarity', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof similarity === 'function').toBeTruthy();
|
||||
expect(similarity([1, 2, 3], [1, 2, 4])).toEqual([1, 2]); //t.equal(similarity(args..), 'Expected');
|
||||
});
|
||||
9
test6/size/size.js
Normal file
9
test6/size/size.js
Normal file
@ -0,0 +1,9 @@
|
||||
const size = val =>
|
||||
Array.isArray(val)
|
||||
? val.length
|
||||
: val && typeof val === 'object'
|
||||
? val.size || val.length || Object.keys(val).length
|
||||
: typeof val === 'string'
|
||||
? new Blob([val]).size
|
||||
: 0;
|
||||
module.exports = size;
|
||||
11
test6/size/size.test.js
Normal file
11
test6/size/size.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const size = require('./size.js');
|
||||
|
||||
test('Testing size', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof size === 'function').toBeTruthy();
|
||||
expect(size([1, 2, 3, 4, 5])).toBe(5);
|
||||
// t.equal(size('size'), 4, "Get size of arrays, objects or strings."); DOESN'T WORK IN NODE ENV
|
||||
expect(size({ one: 1, two: 2, three: 3 })).toBe(3);
|
||||
});
|
||||
2
test6/sleep/sleep.js
Normal file
2
test6/sleep/sleep.js
Normal file
@ -0,0 +1,2 @@
|
||||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||
module.exports = sleep;
|
||||
11
test6/sleep/sleep.test.js
Normal file
11
test6/sleep/sleep.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const sleep = require('./sleep.js');
|
||||
|
||||
test('Testing sleep', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof sleep === 'function').toBeTruthy();
|
||||
async function sleepyWork() {
|
||||
await sleep(1000);
|
||||
}
|
||||
});
|
||||
5
test6/smoothScroll/smoothScroll.js
Normal file
5
test6/smoothScroll/smoothScroll.js
Normal file
@ -0,0 +1,5 @@
|
||||
const smoothScroll = element =>
|
||||
document.querySelector(element).scrollIntoView({
|
||||
behavior: 'smooth'
|
||||
});
|
||||
module.exports = smoothScroll;
|
||||
8
test6/smoothScroll/smoothScroll.test.js
Normal file
8
test6/smoothScroll/smoothScroll.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const smoothScroll = require('./smoothScroll.js');
|
||||
|
||||
test('Testing smoothScroll', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof smoothScroll === 'function').toBeTruthy();
|
||||
});
|
||||
29
test6/solveRPN/solveRPN.js
Normal file
29
test6/solveRPN/solveRPN.js
Normal file
@ -0,0 +1,29 @@
|
||||
const solveRPN = rpn => {
|
||||
const OPERATORS = {
|
||||
'*': (a, b) => a * b,
|
||||
'+': (a, b) => a + b,
|
||||
'-': (a, b) => a - b,
|
||||
'/': (a, b) => a / b,
|
||||
'**': (a, b) => a ** b
|
||||
};
|
||||
const [stack, solve] = [
|
||||
[],
|
||||
rpn
|
||||
.replace(/\^/g, '**')
|
||||
.split(/\s+/g)
|
||||
.filter(el => !/\s+/.test(el) && el !== '')
|
||||
];
|
||||
solve.forEach(symbol => {
|
||||
if (!isNaN(parseFloat(symbol)) && isFinite(symbol)) {
|
||||
stack.push(symbol);
|
||||
} else if (Object.keys(OPERATORS).includes(symbol)) {
|
||||
const [a, b] = [stack.pop(), stack.pop()];
|
||||
stack.push(OPERATORS[symbol](parseFloat(b), parseFloat(a)));
|
||||
} else {
|
||||
throw `${symbol} is not a recognized symbol`;
|
||||
}
|
||||
});
|
||||
if (stack.length === 1) return stack.pop();
|
||||
else throw `${rpn} is not a proper RPN. Please check it and try again`;
|
||||
};
|
||||
module.exports = solveRPN;
|
||||
8
test6/solveRPN/solveRPN.test.js
Normal file
8
test6/solveRPN/solveRPN.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const solveRPN = require('./solveRPN.js');
|
||||
|
||||
test('Testing solveRPN', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof solveRPN === 'function').toBeTruthy();
|
||||
});
|
||||
2
test6/sortCharactersInString/sortCharactersInString.js
Normal file
2
test6/sortCharactersInString/sortCharactersInString.js
Normal file
@ -0,0 +1,2 @@
|
||||
const sortCharactersInString = str => [...str].sort((a, b) => a.localeCompare(b)).join('');
|
||||
module.exports = sortCharactersInString;
|
||||
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const sortCharactersInString = require('./sortCharactersInString.js');
|
||||
|
||||
test('Testing sortCharactersInString', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof sortCharactersInString === 'function').toBeTruthy();
|
||||
expect(sortCharactersInString('cabbage')).toBe('aabbceg');
|
||||
});
|
||||
6
test6/sortedIndex/sortedIndex.js
Normal file
6
test6/sortedIndex/sortedIndex.js
Normal file
@ -0,0 +1,6 @@
|
||||
const sortedIndex = (arr, n) => {
|
||||
const isDescending = arr[0] > arr[arr.length - 1];
|
||||
const index = arr.findIndex(el => (isDescending ? n >= el : n <= el));
|
||||
return index === -1 ? arr.length : index;
|
||||
};
|
||||
module.exports = sortedIndex;
|
||||
10
test6/sortedIndex/sortedIndex.test.js
Normal file
10
test6/sortedIndex/sortedIndex.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const sortedIndex = require('./sortedIndex.js');
|
||||
|
||||
test('Testing sortedIndex', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof sortedIndex === 'function').toBeTruthy();
|
||||
expect(sortedIndex([5, 3, 2, 1], 4)).toBe(1);
|
||||
expect(sortedIndex([30, 50], 40)).toBe(1);
|
||||
});
|
||||
7
test6/sortedIndexBy/sortedIndexBy.js
Normal file
7
test6/sortedIndexBy/sortedIndexBy.js
Normal file
@ -0,0 +1,7 @@
|
||||
const sortedIndexBy = (arr, n, fn) => {
|
||||
const isDescending = fn(arr[0]) > fn(arr[arr.length - 1]);
|
||||
const val = fn(n);
|
||||
const index = arr.findIndex(el => (isDescending ? val >= fn(el) : val <= fn(el)));
|
||||
return index === -1 ? arr.length : index;
|
||||
};
|
||||
module.exports = sortedIndexBy;
|
||||
9
test6/sortedIndexBy/sortedIndexBy.test.js
Normal file
9
test6/sortedIndexBy/sortedIndexBy.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const sortedIndexBy = require('./sortedIndexBy.js');
|
||||
|
||||
test('Testing sortedIndexBy', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof sortedIndexBy === 'function').toBeTruthy();
|
||||
expect(sortedIndexBy([{ x: 4 }, { x: 5 }], { x: 4 }, o => o.x)).toBe(0);
|
||||
});
|
||||
6
test6/sortedLastIndex/sortedLastIndex.js
Normal file
6
test6/sortedLastIndex/sortedLastIndex.js
Normal file
@ -0,0 +1,6 @@
|
||||
const sortedLastIndex = (arr, n) => {
|
||||
const isDescending = arr[0] > arr[arr.length - 1];
|
||||
const index = arr.reverse().findIndex(el => (isDescending ? n <= el : n >= el));
|
||||
return index === -1 ? 0 : arr.length - index;
|
||||
};
|
||||
module.exports = sortedLastIndex;
|
||||
9
test6/sortedLastIndex/sortedLastIndex.test.js
Normal file
9
test6/sortedLastIndex/sortedLastIndex.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const sortedLastIndex = require('./sortedLastIndex.js');
|
||||
|
||||
test('Testing sortedLastIndex', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof sortedLastIndex === 'function').toBeTruthy();
|
||||
expect(sortedLastIndex([10, 20, 30, 30, 40], 30)).toBe(4);
|
||||
});
|
||||
10
test6/sortedLastIndexBy/sortedLastIndexBy.js
Normal file
10
test6/sortedLastIndexBy/sortedLastIndexBy.js
Normal file
@ -0,0 +1,10 @@
|
||||
const sortedLastIndexBy = (arr, n, fn) => {
|
||||
const isDescending = fn(arr[0]) > fn(arr[arr.length - 1]);
|
||||
const val = fn(n);
|
||||
const index = arr
|
||||
.map(fn)
|
||||
.reverse()
|
||||
.findIndex(el => (isDescending ? val <= el : val >= el));
|
||||
return index === -1 ? 0 : arr.length - index;
|
||||
};
|
||||
module.exports = sortedLastIndexBy;
|
||||
9
test6/sortedLastIndexBy/sortedLastIndexBy.test.js
Normal file
9
test6/sortedLastIndexBy/sortedLastIndexBy.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const sortedLastIndexBy = require('./sortedLastIndexBy.js');
|
||||
|
||||
test('Testing sortedLastIndexBy', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof sortedLastIndexBy === 'function').toBeTruthy();
|
||||
expect(sortedLastIndexBy([{ x: 4 }, { x: 5 }], { x: 4 }, o => o.x)).toBe(1);
|
||||
});
|
||||
6
test6/speechSynthesis/speechSynthesis.js
Normal file
6
test6/speechSynthesis/speechSynthesis.js
Normal file
@ -0,0 +1,6 @@
|
||||
const speechSynthesis = message => {
|
||||
const msg = new SpeechSynthesisUtterance(message);
|
||||
msg.voice = window.speechSynthesis.getVoices()[0];
|
||||
window.speechSynthesis.speak(msg);
|
||||
};
|
||||
module.exports = speechSynthesis;
|
||||
8
test6/speechSynthesis/speechSynthesis.test.js
Normal file
8
test6/speechSynthesis/speechSynthesis.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const speechSynthesis = require('./speechSynthesis.js');
|
||||
|
||||
test('Testing speechSynthesis', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof speechSynthesis === 'function').toBeTruthy();
|
||||
});
|
||||
2
test6/splitLines/splitLines.js
Normal file
2
test6/splitLines/splitLines.js
Normal file
@ -0,0 +1,2 @@
|
||||
const splitLines = str => str.split(/\r?\n/);
|
||||
module.exports = splitLines;
|
||||
9
test6/splitLines/splitLines.test.js
Normal file
9
test6/splitLines/splitLines.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const splitLines = require('./splitLines.js');
|
||||
|
||||
test('Testing splitLines', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof splitLines === 'function').toBeTruthy();
|
||||
expect(splitLines('This\nis a\nmultiline\nstring.\n')).toEqual(['This', 'is a', 'multiline', 'string.' , '']);
|
||||
});
|
||||
2
test6/spreadOver/spreadOver.js
Normal file
2
test6/spreadOver/spreadOver.js
Normal file
@ -0,0 +1,2 @@
|
||||
const spreadOver = fn => argsArr => fn(...argsArr);
|
||||
module.exports = spreadOver;
|
||||
10
test6/spreadOver/spreadOver.test.js
Normal file
10
test6/spreadOver/spreadOver.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const spreadOver = require('./spreadOver.js');
|
||||
|
||||
test('Testing spreadOver', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof spreadOver === 'function').toBeTruthy();
|
||||
const arrayMax = spreadOver(Math.max);
|
||||
expect(arrayMax([1, 2, 3])).toBe(3);
|
||||
});
|
||||
6
test6/stableSort/stableSort.js
Normal file
6
test6/stableSort/stableSort.js
Normal file
@ -0,0 +1,6 @@
|
||||
const stableSort = (arr, compare) =>
|
||||
arr
|
||||
.map((item, index) => ({ item, index }))
|
||||
.sort((a, b) => compare(a.item, b.item) || a.index - b.index)
|
||||
.map(({ item }) => item);
|
||||
module.exports = stableSort;
|
||||
16
test6/stableSort/stableSort.test.js
Normal file
16
test6/stableSort/stableSort.test.js
Normal file
@ -0,0 +1,16 @@
|
||||
const expect = require('expect');
|
||||
const stableSort = require('./stableSort.js');
|
||||
|
||||
test('Testing stableSort', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof stableSort === 'function').toBeTruthy();
|
||||
//t.deepEqual(stableSort(args..), 'Expected');
|
||||
//t.equal(stableSort(args..), 'Expected');
|
||||
//t.false(stableSort(args..), 'Expected');
|
||||
//t.throws(stableSort(args..), 'Expected');
|
||||
|
||||
const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
const compare = () => 0;
|
||||
expect(stableSort(arr, compare)).toEqual(arr);
|
||||
});
|
||||
8
test6/standardDeviation/standardDeviation.js
Normal file
8
test6/standardDeviation/standardDeviation.js
Normal file
@ -0,0 +1,8 @@
|
||||
const standardDeviation = (arr, usePopulation = false) => {
|
||||
const mean = arr.reduce((acc, val) => acc + val, 0) / arr.length;
|
||||
return Math.sqrt(
|
||||
arr.reduce((acc, val) => acc.concat((val - mean) ** 2), []).reduce((acc, val) => acc + val, 0) /
|
||||
(arr.length - (usePopulation ? 0 : 1))
|
||||
);
|
||||
};
|
||||
module.exports = standardDeviation;
|
||||
10
test6/standardDeviation/standardDeviation.test.js
Normal file
10
test6/standardDeviation/standardDeviation.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const standardDeviation = require('./standardDeviation.js');
|
||||
|
||||
test('Testing standardDeviation', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof standardDeviation === 'function').toBeTruthy();
|
||||
expect(standardDeviation([10, 2, 38, 23, 38, 23, 21])).toBe(13.284434142114991);
|
||||
expect(standardDeviation([10, 2, 38, 23, 38, 23, 21], true)).toBe(12.29899614287479);
|
||||
});
|
||||
11
test6/stringPermutations/stringPermutations.js
Normal file
11
test6/stringPermutations/stringPermutations.js
Normal file
@ -0,0 +1,11 @@
|
||||
const stringPermutations = str => {
|
||||
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
|
||||
return str
|
||||
.split('')
|
||||
.reduce(
|
||||
(acc, letter, i) =>
|
||||
acc.concat(stringPermutations(str.slice(0, i) + str.slice(i + 1)).map(val => letter + val)),
|
||||
[]
|
||||
);
|
||||
};
|
||||
module.exports = stringPermutations;
|
||||
11
test6/stringPermutations/stringPermutations.test.js
Normal file
11
test6/stringPermutations/stringPermutations.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const stringPermutations = require('./stringPermutations.js');
|
||||
|
||||
test('Testing stringPermutations', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof stringPermutations === 'function').toBeTruthy();
|
||||
expect(stringPermutations('abc')).toEqual(['abc','acb','bac','bca','cab','cba']);
|
||||
expect(stringPermutations('a')).toEqual(['a']);
|
||||
expect(stringPermutations('')).toEqual(['']);
|
||||
});
|
||||
2
test6/stripHTMLTags/stripHTMLTags.js
Normal file
2
test6/stripHTMLTags/stripHTMLTags.js
Normal file
@ -0,0 +1,2 @@
|
||||
const stripHTMLTags = str => str.replace(/<[^>]*>/g, '');
|
||||
module.exports = stripHTMLTags;
|
||||
9
test6/stripHTMLTags/stripHTMLTags.test.js
Normal file
9
test6/stripHTMLTags/stripHTMLTags.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const stripHTMLTags = require('./stripHTMLTags.js');
|
||||
|
||||
test('Testing stripHTMLTags', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof stripHTMLTags === 'function').toBeTruthy();
|
||||
expect(stripHTMLTags('<p><em>lorem</em> <strong>ipsum</strong></p><img /><br>')).toBe('lorem ipsum');
|
||||
});
|
||||
2
test6/sum/sum.js
Normal file
2
test6/sum/sum.js
Normal file
@ -0,0 +1,2 @@
|
||||
const sum = (...arr) => [...arr].reduce((acc, val) => acc + val, 0);
|
||||
module.exports = sum;
|
||||
9
test6/sum/sum.test.js
Normal file
9
test6/sum/sum.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const sum = require('./sum.js');
|
||||
|
||||
test('Testing sum', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof sum === 'function').toBeTruthy();
|
||||
expect(sum(...[1, 2, 3, 4])).toBe(10);
|
||||
});
|
||||
3
test6/sumBy/sumBy.js
Normal file
3
test6/sumBy/sumBy.js
Normal file
@ -0,0 +1,3 @@
|
||||
const sumBy = (arr, fn) =>
|
||||
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0);
|
||||
module.exports = sumBy;
|
||||
8
test6/sumBy/sumBy.test.js
Normal file
8
test6/sumBy/sumBy.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const sumBy = require('./sumBy.js');
|
||||
|
||||
test('Testing sumBy', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof sumBy === 'function').toBeTruthy();
|
||||
});
|
||||
6
test6/sumPower/sumPower.js
Normal file
6
test6/sumPower/sumPower.js
Normal file
@ -0,0 +1,6 @@
|
||||
const sumPower = (end, power = 2, start = 1) =>
|
||||
Array(end + 1 - start)
|
||||
.fill(0)
|
||||
.map((x, i) => (i + start) ** power)
|
||||
.reduce((a, b) => a + b, 0);
|
||||
module.exports = sumPower;
|
||||
11
test6/sumPower/sumPower.test.js
Normal file
11
test6/sumPower/sumPower.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const sumPower = require('./sumPower.js');
|
||||
|
||||
test('Testing sumPower', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof sumPower === 'function').toBeTruthy();
|
||||
expect(sumPower(10)).toBe(385);
|
||||
expect(sumPower(10, 3)).toBe(3025);
|
||||
expect(sumPower(10, 3, 5)).toBe(2925);
|
||||
});
|
||||
6
test6/symmetricDifference/symmetricDifference.js
Normal file
6
test6/symmetricDifference/symmetricDifference.js
Normal file
@ -0,0 +1,6 @@
|
||||
const symmetricDifference = (a, b) => {
|
||||
const sA = new Set(a),
|
||||
sB = new Set(b);
|
||||
return [...a.filter(x => !sB.has(x)), ...b.filter(x => !sA.has(x))];
|
||||
};
|
||||
module.exports = symmetricDifference;
|
||||
9
test6/symmetricDifference/symmetricDifference.test.js
Normal file
9
test6/symmetricDifference/symmetricDifference.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const symmetricDifference = require('./symmetricDifference.js');
|
||||
|
||||
test('Testing symmetricDifference', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof symmetricDifference === 'function').toBeTruthy();
|
||||
expect(symmetricDifference([1, 2, 3], [1, 2, 4])).toEqual([3, 4]);
|
||||
});
|
||||
6
test6/symmetricDifferenceBy/symmetricDifferenceBy.js
Normal file
6
test6/symmetricDifferenceBy/symmetricDifferenceBy.js
Normal file
@ -0,0 +1,6 @@
|
||||
const symmetricDifferenceBy = (a, b, fn) => {
|
||||
const sA = new Set(a.map(v => fn(v))),
|
||||
sB = new Set(b.map(v => fn(v)));
|
||||
return [...a.filter(x => !sB.has(fn(x))), ...b.filter(x => !sA.has(fn(x)))];
|
||||
};
|
||||
module.exports = symmetricDifferenceBy;
|
||||
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const symmetricDifferenceBy = require('./symmetricDifferenceBy.js');
|
||||
|
||||
test('Testing symmetricDifferenceBy', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof symmetricDifferenceBy === 'function').toBeTruthy();
|
||||
expect(symmetricDifferenceBy([2.1, 1.2], [2.3, 3.4], Math.floor)).toEqual([ 1.2, 3.4 ]);
|
||||
});
|
||||
5
test6/symmetricDifferenceWith/symmetricDifferenceWith.js
Normal file
5
test6/symmetricDifferenceWith/symmetricDifferenceWith.js
Normal file
@ -0,0 +1,5 @@
|
||||
const symmetricDifferenceWith = (arr, val, comp) => [
|
||||
...arr.filter(a => val.findIndex(b => comp(a, b)) === -1),
|
||||
...val.filter(a => arr.findIndex(b => comp(a, b)) === -1)
|
||||
];
|
||||
module.exports = symmetricDifferenceWith;
|
||||
@ -0,0 +1,13 @@
|
||||
const expect = require('expect');
|
||||
const symmetricDifferenceWith = require('./symmetricDifferenceWith.js');
|
||||
|
||||
test('Testing symmetricDifferenceWith', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof symmetricDifferenceWith === 'function').toBeTruthy();
|
||||
expect(symmetricDifferenceWith(
|
||||
[1, 1.2, 1.5, 3, 0],
|
||||
[1.9, 3, 0, 3.9],
|
||||
(a, b) => Math.round(a) === Math.round(b)
|
||||
)).toEqual([1, 1.2, 3.9]);
|
||||
});
|
||||
2
test6/tail/tail.js
Normal file
2
test6/tail/tail.js
Normal file
@ -0,0 +1,2 @@
|
||||
const tail = arr => (arr.length > 1 ? arr.slice(1) : arr);
|
||||
module.exports = tail;
|
||||
10
test6/tail/tail.test.js
Normal file
10
test6/tail/tail.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const tail = require('./tail.js');
|
||||
|
||||
test('Testing tail', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof tail === 'function').toBeTruthy();
|
||||
expect(tail([1, 2, 3])).toEqual([2, 3]);
|
||||
expect(tail([1])).toEqual([1]);
|
||||
});
|
||||
2
test6/take/take.js
Normal file
2
test6/take/take.js
Normal file
@ -0,0 +1,2 @@
|
||||
const take = (arr, n = 1) => arr.slice(0, n);
|
||||
module.exports = take;
|
||||
10
test6/take/take.test.js
Normal file
10
test6/take/take.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const take = require('./take.js');
|
||||
|
||||
test('Testing take', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof take === 'function').toBeTruthy();
|
||||
expect(take([1, 2, 3], 5)).toEqual([1, 2, 3]);
|
||||
expect(take([1, 2, 3], 0)).toEqual([]);
|
||||
});
|
||||
2
test6/takeRight/takeRight.js
Normal file
2
test6/takeRight/takeRight.js
Normal file
@ -0,0 +1,2 @@
|
||||
const takeRight = (arr, n = 1) => arr.slice(arr.length - n, arr.length);
|
||||
module.exports = takeRight;
|
||||
10
test6/takeRight/takeRight.test.js
Normal file
10
test6/takeRight/takeRight.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const takeRight = require('./takeRight.js');
|
||||
|
||||
test('Testing takeRight', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof takeRight === 'function').toBeTruthy();
|
||||
expect(takeRight([1, 2, 3], 2)).toEqual([2, 3]);
|
||||
expect(takeRight([1, 2, 3])).toEqual([3]);
|
||||
});
|
||||
6
test6/takeRightWhile/takeRightWhile.js
Normal file
6
test6/takeRightWhile/takeRightWhile.js
Normal file
@ -0,0 +1,6 @@
|
||||
const takeRightWhile = (arr, func) => {
|
||||
for (let i of arr.reverse().keys())
|
||||
if (func(arr[i])) return arr.reverse().slice(arr.length - i, arr.length);
|
||||
return arr;
|
||||
};
|
||||
module.exports = takeRightWhile;
|
||||
9
test6/takeRightWhile/takeRightWhile.test.js
Normal file
9
test6/takeRightWhile/takeRightWhile.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const takeRightWhile = require('./takeRightWhile.js');
|
||||
|
||||
test('Testing takeRightWhile', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof takeRightWhile === 'function').toBeTruthy();
|
||||
expect(takeRightWhile([1, 2, 3, 4], n => n < 3)).toEqual([3, 4]);
|
||||
});
|
||||
5
test6/takeWhile/takeWhile.js
Normal file
5
test6/takeWhile/takeWhile.js
Normal file
@ -0,0 +1,5 @@
|
||||
const takeWhile = (arr, func) => {
|
||||
for (const [i, val] of arr.entries()) if (func(val)) return arr.slice(0, i);
|
||||
return arr;
|
||||
};
|
||||
module.exports = takeWhile;
|
||||
9
test6/takeWhile/takeWhile.test.js
Normal file
9
test6/takeWhile/takeWhile.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const takeWhile = require('./takeWhile.js');
|
||||
|
||||
test('Testing takeWhile', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof takeWhile === 'function').toBeTruthy();
|
||||
expect(takeWhile([1, 2, 3, 4], n => n >= 3)).toEqual([1, 2]);
|
||||
});
|
||||
21
test6/throttle/throttle.js
Normal file
21
test6/throttle/throttle.js
Normal file
@ -0,0 +1,21 @@
|
||||
const throttle = (fn, wait) => {
|
||||
let inThrottle, lastFn, lastTime;
|
||||
return function() {
|
||||
const context = this,
|
||||
args = arguments;
|
||||
if (!inThrottle) {
|
||||
fn.apply(context, args);
|
||||
lastTime = Date.now();
|
||||
inThrottle = true;
|
||||
} else {
|
||||
clearTimeout(lastFn);
|
||||
lastFn = setTimeout(function() {
|
||||
if (Date.now() - lastTime >= wait) {
|
||||
fn.apply(context, args);
|
||||
lastTime = Date.now();
|
||||
}
|
||||
}, wait - (Date.now() - lastTime));
|
||||
}
|
||||
};
|
||||
};
|
||||
module.exports = throttle;
|
||||
8
test6/throttle/throttle.test.js
Normal file
8
test6/throttle/throttle.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const throttle = require('./throttle.js');
|
||||
|
||||
test('Testing throttle', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof throttle === 'function').toBeTruthy();
|
||||
});
|
||||
7
test6/timeTaken/timeTaken.js
Normal file
7
test6/timeTaken/timeTaken.js
Normal file
@ -0,0 +1,7 @@
|
||||
const timeTaken = callback => {
|
||||
console.time('timeTaken');
|
||||
const r = callback();
|
||||
console.timeEnd('timeTaken');
|
||||
return r;
|
||||
};
|
||||
module.exports = timeTaken;
|
||||
8
test6/timeTaken/timeTaken.test.js
Normal file
8
test6/timeTaken/timeTaken.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const timeTaken = require('./timeTaken.js');
|
||||
|
||||
test('Testing timeTaken', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof timeTaken === 'function').toBeTruthy();
|
||||
});
|
||||
5
test6/times/times.js
Normal file
5
test6/times/times.js
Normal file
@ -0,0 +1,5 @@
|
||||
const times = (n, fn, context = undefined) => {
|
||||
let i = 0;
|
||||
while (fn.call(context, i) !== false && ++i < n) {}
|
||||
};
|
||||
module.exports = times;
|
||||
11
test6/times/times.test.js
Normal file
11
test6/times/times.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const times = require('./times.js');
|
||||
|
||||
test('Testing times', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof times === 'function').toBeTruthy();
|
||||
var output = '';
|
||||
times(5, i => (output += i));
|
||||
expect(output).toBe('01234');
|
||||
});
|
||||
10
test6/toCamelCase/toCamelCase.js
Normal file
10
test6/toCamelCase/toCamelCase.js
Normal file
@ -0,0 +1,10 @@
|
||||
const toCamelCase = str => {
|
||||
let s =
|
||||
str &&
|
||||
str
|
||||
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
||||
.map(x => x.slice(0, 1).toUpperCase() + x.slice(1).toLowerCase())
|
||||
.join('');
|
||||
return s.slice(0, 1).toLowerCase() + s.slice(1);
|
||||
};
|
||||
module.exports = toCamelCase;
|
||||
21
test6/toCamelCase/toCamelCase.test.js
Normal file
21
test6/toCamelCase/toCamelCase.test.js
Normal file
@ -0,0 +1,21 @@
|
||||
const expect = require('expect');
|
||||
const toCamelCase = require('./toCamelCase.js');
|
||||
|
||||
test('Testing toCamelCase', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof toCamelCase === 'function').toBeTruthy();
|
||||
expect(toCamelCase('some_database_field_name')).toBe('someDatabaseFieldName');
|
||||
expect(toCamelCase('Some label that needs to be camelized')).toBe('someLabelThatNeedsToBeCamelized');
|
||||
expect(toCamelCase('some-javascript-property')).toBe('someJavascriptProperty');
|
||||
expect(toCamelCase('some-mixed_string with spaces_underscores-and-hyphens')).toBe('someMixedStringWithSpacesUnderscoresAndHyphens');
|
||||
expect(() => toCamelCase()).toThrow();
|
||||
expect(() => toCamelCase([])).toThrow();
|
||||
expect(() => toCamelCase({})).toThrow();
|
||||
expect(() => toCamelCase(123)).toThrow();
|
||||
|
||||
let start = new Date().getTime();
|
||||
toCamelCase('some-mixed_string with spaces_underscores-and-hyphens');
|
||||
let end = new Date().getTime();
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
});
|
||||
3
test6/toCurrency/toCurrency.js
Normal file
3
test6/toCurrency/toCurrency.js
Normal file
@ -0,0 +1,3 @@
|
||||
const toCurrency = (n, curr, LanguageFormat = undefined) =>
|
||||
Intl.NumberFormat(LanguageFormat, { style: 'currency', currency: curr }).format(n);
|
||||
module.exports = toCurrency;
|
||||
12
test6/toCurrency/toCurrency.test.js
Normal file
12
test6/toCurrency/toCurrency.test.js
Normal file
@ -0,0 +1,12 @@
|
||||
const expect = require('expect');
|
||||
const toCurrency = require('./toCurrency.js');
|
||||
|
||||
test('Testing toCurrency', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof toCurrency === 'function').toBeTruthy();
|
||||
expect(toCurrency(123456.789, 'EUR')).toBe('€ 123,456.79');
|
||||
expect(toCurrency(123456.789, 'USD', 'en-us')).toBe('$123,456.79');
|
||||
//t.equal(toCurrency(123456.789, 'USD', 'fa'), '۱۲۳٬۴۵۶٫۷۹ $', 'currency: US Dollar | currencyLangFormat: Farsi'); - These break in node
|
||||
expect(toCurrency(322342436423.2435, 'JPY')).toBe('JP¥ 322,342,436,423');
|
||||
});
|
||||
2
test6/toDecimalMark/toDecimalMark.js
Normal file
2
test6/toDecimalMark/toDecimalMark.js
Normal file
@ -0,0 +1,2 @@
|
||||
const toDecimalMark = num => num.toLocaleString('en-US');
|
||||
module.exports = toDecimalMark;
|
||||
9
test6/toDecimalMark/toDecimalMark.test.js
Normal file
9
test6/toDecimalMark/toDecimalMark.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const toDecimalMark = require('./toDecimalMark.js');
|
||||
|
||||
test('Testing toDecimalMark', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof toDecimalMark === 'function').toBeTruthy();
|
||||
expect(toDecimalMark(12305030388.9087)).toBe("12,305,030,388.909");
|
||||
});
|
||||
7
test6/toHash/toHash.js
Normal file
7
test6/toHash/toHash.js
Normal file
@ -0,0 +1,7 @@
|
||||
const toHash = (object, key) =>
|
||||
Array.prototype.reduce.call(
|
||||
object,
|
||||
(acc, data, index) => ((acc[!key ? index : data[key]] = data), acc),
|
||||
{}
|
||||
);
|
||||
module.exports = toHash;
|
||||
8
test6/toHash/toHash.test.js
Normal file
8
test6/toHash/toHash.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const toHash = require('./toHash.js');
|
||||
|
||||
test('Testing toHash', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof toHash === 'function').toBeTruthy();
|
||||
});
|
||||
7
test6/toKebabCase/toKebabCase.js
Normal file
7
test6/toKebabCase/toKebabCase.js
Normal file
@ -0,0 +1,7 @@
|
||||
const toKebabCase = str =>
|
||||
str &&
|
||||
str
|
||||
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
||||
.map(x => x.toLowerCase())
|
||||
.join('-');
|
||||
module.exports = toKebabCase;
|
||||
25
test6/toKebabCase/toKebabCase.test.js
Normal file
25
test6/toKebabCase/toKebabCase.test.js
Normal file
@ -0,0 +1,25 @@
|
||||
const expect = require('expect');
|
||||
const toKebabCase = require('./toKebabCase.js');
|
||||
|
||||
test('Testing toKebabCase', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof toKebabCase === 'function').toBeTruthy();
|
||||
expect(toKebabCase('camelCase')).toBe('camel-case');
|
||||
expect(toKebabCase('some text')).toBe('some-text');
|
||||
expect(toKebabCase('some-mixed-string With spaces-underscores-and-hyphens')).toBe('some-mixed-string-with-spaces-underscores-and-hyphens');
|
||||
expect(
|
||||
toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML')
|
||||
).toBe(
|
||||
'i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html'
|
||||
);
|
||||
expect(toKebabCase()).toBe(undefined);
|
||||
expect(() => toKebabCase([])).toThrow();
|
||||
expect(() => toKebabCase({})).toThrow();
|
||||
expect(() => toKebabCase(123)).toThrow();
|
||||
|
||||
let start = new Date().getTime();
|
||||
toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML');
|
||||
let end = new Date().getTime();
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user