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:
5
test4/JSONToDate/JSONToDate.js
Normal file
5
test4/JSONToDate/JSONToDate.js
Normal file
@ -0,0 +1,5 @@
|
||||
const JSONToDate = arr => {
|
||||
const dt = new Date(parseInt(arr.toString().substr(6)));
|
||||
return `${dt.getDate()}/${dt.getMonth() + 1}/${dt.getFullYear()}`;
|
||||
};
|
||||
module.exports = JSONToDate;
|
||||
8
test4/JSONToDate/JSONToDate.test.js
Normal file
8
test4/JSONToDate/JSONToDate.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const JSONToDate = require('./JSONToDate.js');
|
||||
|
||||
test('Testing JSONToDate', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof JSONToDate === 'function').toBeTruthy();
|
||||
});
|
||||
4
test4/JSONToFile/JSONToFile.js
Normal file
4
test4/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;
|
||||
8
test4/JSONToFile/JSONToFile.test.js
Normal file
8
test4/JSONToFile/JSONToFile.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const JSONToFile = require('./JSONToFile.js');
|
||||
|
||||
test('Testing JSONToFile', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof JSONToFile === 'function').toBeTruthy();
|
||||
});
|
||||
6
test4/isPrime/isPrime.js
Normal file
6
test4/isPrime/isPrime.js
Normal file
@ -0,0 +1,6 @@
|
||||
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;
|
||||
};
|
||||
module.exports = isPrime;
|
||||
9
test4/isPrime/isPrime.test.js
Normal file
9
test4/isPrime/isPrime.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const isPrime = require('./isPrime.js');
|
||||
|
||||
test('Testing isPrime', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isPrime === 'function').toBeTruthy();
|
||||
expect(isPrime(11)).toBe(true);
|
||||
});
|
||||
2
test4/isPrimitive/isPrimitive.js
Normal file
2
test4/isPrimitive/isPrimitive.js
Normal file
@ -0,0 +1,2 @@
|
||||
const isPrimitive = val => !['object', 'function'].includes(typeof val) || val === null;
|
||||
module.exports = isPrimitive;
|
||||
23
test4/isPrimitive/isPrimitive.test.js
Normal file
23
test4/isPrimitive/isPrimitive.test.js
Normal file
@ -0,0 +1,23 @@
|
||||
const expect = require('expect');
|
||||
const isPrimitive = require('./isPrimitive.js');
|
||||
|
||||
test('Testing isPrimitive', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isPrimitive === 'function').toBeTruthy();
|
||||
expect(isPrimitive(null)).toBeTruthy();
|
||||
expect(isPrimitive(undefined)).toBeTruthy();
|
||||
expect(isPrimitive('string')).toBeTruthy();
|
||||
expect(isPrimitive(true)).toBeTruthy();
|
||||
expect(isPrimitive(50)).toBeTruthy();
|
||||
expect(isPrimitive('Hello')).toBeTruthy();
|
||||
expect(isPrimitive(false)).toBeTruthy();
|
||||
expect(isPrimitive(Symbol())).toBeTruthy();
|
||||
expect(isPrimitive([1, 2, 3])).toBeFalsy();
|
||||
expect(isPrimitive({ a: 123 })).toBeFalsy();
|
||||
|
||||
let start = new Date().getTime();
|
||||
isPrimitive({ a: 123 });
|
||||
let end = new Date().getTime();
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
});
|
||||
5
test4/isPromiseLike/isPromiseLike.js
Normal file
5
test4/isPromiseLike/isPromiseLike.js
Normal file
@ -0,0 +1,5 @@
|
||||
const isPromiseLike = obj =>
|
||||
obj !== null &&
|
||||
(typeof obj === 'object' || typeof obj === 'function') &&
|
||||
typeof obj.then === 'function';
|
||||
module.exports = isPromiseLike;
|
||||
15
test4/isPromiseLike/isPromiseLike.test.js
Normal file
15
test4/isPromiseLike/isPromiseLike.test.js
Normal file
@ -0,0 +1,15 @@
|
||||
const expect = require('expect');
|
||||
const isPromiseLike = require('./isPromiseLike.js');
|
||||
|
||||
test('Testing isPromiseLike', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isPromiseLike === 'function').toBeTruthy();
|
||||
expect(isPromiseLike({
|
||||
then: function() {
|
||||
return '';
|
||||
}
|
||||
})).toBe(true);
|
||||
expect(isPromiseLike(null)).toBe(false);
|
||||
expect(isPromiseLike({})).toBe(false);
|
||||
});
|
||||
2
test4/isRegExp/isRegExp.js
Normal file
2
test4/isRegExp/isRegExp.js
Normal file
@ -0,0 +1,2 @@
|
||||
const isRegExp = val => val instanceof RegExp;
|
||||
module.exports = isRegExp;
|
||||
8
test4/isRegExp/isRegExp.test.js
Normal file
8
test4/isRegExp/isRegExp.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const isRegExp = require('./isRegExp.js');
|
||||
|
||||
test('Testing isRegExp', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isRegExp === 'function').toBeTruthy();
|
||||
});
|
||||
2
test4/isSet/isSet.js
Normal file
2
test4/isSet/isSet.js
Normal file
@ -0,0 +1,2 @@
|
||||
const isSet = val => val instanceof Set;
|
||||
module.exports = isSet;
|
||||
8
test4/isSet/isSet.test.js
Normal file
8
test4/isSet/isSet.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const isSet = require('./isSet.js');
|
||||
|
||||
test('Testing isSet', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isSet === 'function').toBeTruthy();
|
||||
});
|
||||
5
test4/isSimilar/isSimilar.js
Normal file
5
test4/isSimilar/isSimilar.js
Normal file
@ -0,0 +1,5 @@
|
||||
const isSimilar = (pattern, str) =>
|
||||
[...str].reduce(
|
||||
(matchIndex, char) => char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() ? matchIndex + 1 : matchIndex, 0
|
||||
) === pattern.length ? true : false;
|
||||
module.exports = isSimilar;
|
||||
8
test4/isSimilar/isSimilar.test.js
Normal file
8
test4/isSimilar/isSimilar.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const isSimilar = require('./isSimilar.js');
|
||||
|
||||
test('Testing isSimilar', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isSimilar === 'function').toBeTruthy();
|
||||
});
|
||||
9
test4/isSorted/isSorted.js
Normal file
9
test4/isSorted/isSorted.js
Normal file
@ -0,0 +1,9 @@
|
||||
const isSorted = arr => {
|
||||
let direction = -(arr[0] - arr[1]);
|
||||
for (let [i, val] of arr.entries()) {
|
||||
direction = !direction ? -(arr[i - 1] - arr[i]) : direction;
|
||||
if (i === arr.length - 1) return !direction ? 0 : direction;
|
||||
else if ((val - arr[i + 1]) * direction > 0) return 0;
|
||||
}
|
||||
};
|
||||
module.exports = isSorted;
|
||||
20
test4/isSorted/isSorted.test.js
Normal file
20
test4/isSorted/isSorted.test.js
Normal file
@ -0,0 +1,20 @@
|
||||
const expect = require('expect');
|
||||
const isSorted = require('./isSorted.js');
|
||||
|
||||
test('Testing isSorted', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isSorted === 'function').toBeTruthy();
|
||||
//t.deepEqual(isSorted(args..), 'Expected');
|
||||
expect(isSorted([0, 1, 2])).toBe(1);
|
||||
expect(isSorted([0, 1, 2, 2])).toBe(1);
|
||||
expect(isSorted([-4, -3, -2])).toBe(1);
|
||||
expect(isSorted([0, 0, 1, 2])).toBe(1);
|
||||
expect(isSorted([2, 1, 0])).toBe(-1);
|
||||
expect(isSorted([2, 2, 1, 0])).toBe(-1);
|
||||
expect(isSorted([-2, -3, -4])).toBe(-1);
|
||||
expect(isSorted([2, 1, 0, 0])).toBe(-1);
|
||||
expect(isSorted([])).toBe(undefined);
|
||||
expect(isSorted([1])).toBe(0);
|
||||
expect(isSorted([1, 2, 1])).toBe(0);
|
||||
});
|
||||
2
test4/isString/isString.js
Normal file
2
test4/isString/isString.js
Normal file
@ -0,0 +1,2 @@
|
||||
const isString = val => typeof val === 'string';
|
||||
module.exports = isString;
|
||||
13
test4/isString/isString.test.js
Normal file
13
test4/isString/isString.test.js
Normal file
@ -0,0 +1,13 @@
|
||||
const expect = require('expect');
|
||||
const isString = require('./isString.js');
|
||||
|
||||
test('Testing isString', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isString === 'function').toBeTruthy();
|
||||
expect(isString('foo')).toBe(true);
|
||||
expect(isString('10')).toBe(true);
|
||||
expect(isString('')).toBe(true);
|
||||
expect(isString(10)).toBe(false);
|
||||
expect(isString(true)).toBe(false);
|
||||
});
|
||||
2
test4/isSymbol/isSymbol.js
Normal file
2
test4/isSymbol/isSymbol.js
Normal file
@ -0,0 +1,2 @@
|
||||
const isSymbol = val => typeof val === 'symbol';
|
||||
module.exports = isSymbol;
|
||||
9
test4/isSymbol/isSymbol.test.js
Normal file
9
test4/isSymbol/isSymbol.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const isSymbol = require('./isSymbol.js');
|
||||
|
||||
test('Testing isSymbol', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isSymbol === 'function').toBeTruthy();
|
||||
expect(isSymbol(Symbol('x'))).toBe(true);
|
||||
});
|
||||
2
test4/isTravisCI/isTravisCI.js
Normal file
2
test4/isTravisCI/isTravisCI.js
Normal file
@ -0,0 +1,2 @@
|
||||
const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env;
|
||||
module.exports = isTravisCI;
|
||||
12
test4/isTravisCI/isTravisCI.test.js
Normal file
12
test4/isTravisCI/isTravisCI.test.js
Normal file
@ -0,0 +1,12 @@
|
||||
const expect = require('expect');
|
||||
const isTravisCI = require('./isTravisCI.js');
|
||||
|
||||
test('Testing isTravisCI', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isTravisCI === 'function').toBeTruthy();
|
||||
if(isTravisCI())
|
||||
expect(isTravisCI()).toBeTruthy();
|
||||
else
|
||||
expect(isTravisCI()).toBeFalsy();
|
||||
});
|
||||
2
test4/isTypedArray/isTypedArray.js
Normal file
2
test4/isTypedArray/isTypedArray.js
Normal file
@ -0,0 +1,2 @@
|
||||
const isTypedArray = val => val instanceof TypedArray;
|
||||
module.exports = isTypedArray;
|
||||
8
test4/isTypedArray/isTypedArray.test.js
Normal file
8
test4/isTypedArray/isTypedArray.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const isTypedArray = require('./isTypedArray.js');
|
||||
|
||||
test('Testing isTypedArray', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isTypedArray === 'function').toBeTruthy();
|
||||
});
|
||||
2
test4/isUndefined/isUndefined.js
Normal file
2
test4/isUndefined/isUndefined.js
Normal file
@ -0,0 +1,2 @@
|
||||
const isUndefined = val => val === undefined;
|
||||
module.exports = isUndefined;
|
||||
9
test4/isUndefined/isUndefined.test.js
Normal file
9
test4/isUndefined/isUndefined.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const isUndefined = require('./isUndefined.js');
|
||||
|
||||
test('Testing isUndefined', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isUndefined === 'function').toBeTruthy();
|
||||
expect(isUndefined(undefined)).toBeTruthy();
|
||||
});
|
||||
2
test4/isUpperCase/isUpperCase.js
Normal file
2
test4/isUpperCase/isUpperCase.js
Normal file
@ -0,0 +1,2 @@
|
||||
const isUpperCase = str => str === str.toUpperCase();
|
||||
module.exports = isUpperCase;
|
||||
12
test4/isUpperCase/isUpperCase.test.js
Normal file
12
test4/isUpperCase/isUpperCase.test.js
Normal file
@ -0,0 +1,12 @@
|
||||
const expect = require('expect');
|
||||
const isUpperCase = require('./isUpperCase.js');
|
||||
|
||||
test('Testing isUpperCase', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isUpperCase === 'function').toBeTruthy();
|
||||
//t.deepEqual(isUpperCase(args..), 'Expected');
|
||||
expect(isUpperCase('ABC')).toBe(true);
|
||||
expect(isUpperCase('abc')).toBe(false);
|
||||
expect(isUpperCase('A3@$')).toBe(true);
|
||||
});
|
||||
9
test4/isValidJSON/isValidJSON.js
Normal file
9
test4/isValidJSON/isValidJSON.js
Normal file
@ -0,0 +1,9 @@
|
||||
const isValidJSON = obj => {
|
||||
try {
|
||||
JSON.parse(obj);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
module.exports = isValidJSON;
|
||||
11
test4/isValidJSON/isValidJSON.test.js
Normal file
11
test4/isValidJSON/isValidJSON.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const isValidJSON = require('./isValidJSON.js');
|
||||
|
||||
test('Testing isValidJSON', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isValidJSON === 'function').toBeTruthy();
|
||||
expect(isValidJSON('{"name":"Adam","age":20}')).toBe(true);
|
||||
expect(isValidJSON('{"name":"Adam",age:"20"}')).toBe(false);
|
||||
expect(isValidJSON(null)).toBe(true);
|
||||
});
|
||||
2
test4/isWeakMap/isWeakMap.js
Normal file
2
test4/isWeakMap/isWeakMap.js
Normal file
@ -0,0 +1,2 @@
|
||||
const isWeakMap = val => val instanceof WeakMap;
|
||||
module.exports = isWeakMap;
|
||||
8
test4/isWeakMap/isWeakMap.test.js
Normal file
8
test4/isWeakMap/isWeakMap.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const isWeakMap = require('./isWeakMap.js');
|
||||
|
||||
test('Testing isWeakMap', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isWeakMap === 'function').toBeTruthy();
|
||||
});
|
||||
2
test4/isWeakSet/isWeakSet.js
Normal file
2
test4/isWeakSet/isWeakSet.js
Normal file
@ -0,0 +1,2 @@
|
||||
const isWeakSet = val => val instanceof WeakSet;
|
||||
module.exports = isWeakSet;
|
||||
8
test4/isWeakSet/isWeakSet.test.js
Normal file
8
test4/isWeakSet/isWeakSet.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const isWeakSet = require('./isWeakSet.js');
|
||||
|
||||
test('Testing isWeakSet', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof isWeakSet === 'function').toBeTruthy();
|
||||
});
|
||||
11
test4/join/join.js
Normal file
11
test4/join/join.js
Normal file
@ -0,0 +1,11 @@
|
||||
const join = (arr, separator = ',', end = separator) =>
|
||||
arr.reduce(
|
||||
(acc, val, i) =>
|
||||
i === arr.length - 2
|
||||
? acc + val + end
|
||||
: i === arr.length - 1
|
||||
? acc + val
|
||||
: acc + val + separator,
|
||||
''
|
||||
);
|
||||
module.exports = join;
|
||||
11
test4/join/join.test.js
Normal file
11
test4/join/join.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const join = require('./join.js');
|
||||
|
||||
test('Testing join', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof join === 'function').toBeTruthy();
|
||||
expect(join(['pen', 'pineapple', 'apple', 'pen'], ',', '&')).toEqual("pen,pineapple,apple&pen");
|
||||
expect(join(['pen', 'pineapple', 'apple', 'pen'], ',')).toEqual("pen,pineapple,apple,pen");
|
||||
expect(join(['pen', 'pineapple', 'apple', 'pen'])).toEqual("pen,pineapple,apple,pen");
|
||||
});
|
||||
2
test4/last/last.js
Normal file
2
test4/last/last.js
Normal file
@ -0,0 +1,2 @@
|
||||
const last = arr => arr[arr.length - 1];
|
||||
module.exports = last;
|
||||
20
test4/last/last.test.js
Normal file
20
test4/last/last.test.js
Normal file
@ -0,0 +1,20 @@
|
||||
const expect = require('expect');
|
||||
const last = require('./last.js');
|
||||
|
||||
test('Testing last', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof last === 'function').toBeTruthy();
|
||||
expect(last({ a: 1234}) === undefined).toBeTruthy();
|
||||
expect(last([1, 2, 3])).toBe(3);
|
||||
expect(last({ 0: false})).toBe(undefined);
|
||||
expect(last('String')).toBe('g');
|
||||
expect(() => last(null)).toThrow();
|
||||
expect(() => last(undefined)).toThrow();
|
||||
expect(() => last()).toThrow();
|
||||
|
||||
let start = new Date().getTime();
|
||||
last([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]);
|
||||
let end = new Date().getTime();
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
});
|
||||
6
test4/lcm/lcm.js
Normal file
6
test4/lcm/lcm.js
Normal file
@ -0,0 +1,6 @@
|
||||
const lcm = (...arr) => {
|
||||
const gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
||||
const _lcm = (x, y) => x * y / gcd(x, y);
|
||||
return [...arr].reduce((a, b) => _lcm(a, b));
|
||||
};
|
||||
module.exports = lcm;
|
||||
10
test4/lcm/lcm.test.js
Normal file
10
test4/lcm/lcm.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const lcm = require('./lcm.js');
|
||||
|
||||
test('Testing lcm', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof lcm === 'function').toBeTruthy();
|
||||
expect(lcm(12, 7)).toBe(84);
|
||||
expect(lcm(...[1, 3, 4, 5])).toBe(60);
|
||||
});
|
||||
18
test4/levenshteinDistance/levenshteinDistance.js
Normal file
18
test4/levenshteinDistance/levenshteinDistance.js
Normal file
@ -0,0 +1,18 @@
|
||||
const levenshteinDistance = (string1, string2) => {
|
||||
if(string1.length === 0) return string2.length;
|
||||
if(string2.length === 0) return string1.length;
|
||||
let matrix = Array(string2.length + 1).fill(0).map((x,i) => [i]);
|
||||
matrix[0] = Array(string1.length + 1).fill(0).map((x,i) => i);
|
||||
for(let i = 1; i <= string2.length; i++){
|
||||
for(let j = 1; j<=string1.length; j++){
|
||||
if(string2[i-1] === string1[j-1]){
|
||||
matrix[i][j] = matrix[i-1][j-1];
|
||||
}
|
||||
else{
|
||||
matrix[i][j] = Math.min(matrix[i-1][j-1]+1, matrix[i][j-1]+1, matrix[i-1][j]+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return matrix[string2.length][string1.length];
|
||||
};
|
||||
module.exports = levenshteinDistance;
|
||||
8
test4/levenshteinDistance/levenshteinDistance.test.js
Normal file
8
test4/levenshteinDistance/levenshteinDistance.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const levenshteinDistance = require('./levenshteinDistance.js');
|
||||
|
||||
test('Testing levenshteinDistance', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof levenshteinDistance === 'function').toBeTruthy();
|
||||
});
|
||||
2
test4/longestItem/longestItem.js
Normal file
2
test4/longestItem/longestItem.js
Normal file
@ -0,0 +1,2 @@
|
||||
const longestItem = (...vals) => [...vals].sort((a, b) => b.length - a.length)[0];
|
||||
module.exports = longestItem;
|
||||
9
test4/longestItem/longestItem.test.js
Normal file
9
test4/longestItem/longestItem.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const longestItem = require('./longestItem.js');
|
||||
|
||||
test('Testing longestItem', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof longestItem === 'function').toBeTruthy();
|
||||
expect(longestItem('this', 'is', 'a', 'testcase')).toEqual('testcase');
|
||||
});
|
||||
6
test4/lowercaseKeys/lowercaseKeys.js
Normal file
6
test4/lowercaseKeys/lowercaseKeys.js
Normal file
@ -0,0 +1,6 @@
|
||||
const lowercaseKeys = obj =>
|
||||
Object.keys(obj).reduce((acc, key) => {
|
||||
acc[key.toLowerCase()] = obj[key];
|
||||
return acc;
|
||||
}, {});
|
||||
module.exports = lowercaseKeys;
|
||||
12
test4/lowercaseKeys/lowercaseKeys.test.js
Normal file
12
test4/lowercaseKeys/lowercaseKeys.test.js
Normal file
@ -0,0 +1,12 @@
|
||||
const expect = require('expect');
|
||||
const lowercaseKeys = require('./lowercaseKeys.js');
|
||||
|
||||
test('Testing lowercaseKeys', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof lowercaseKeys === 'function').toBeTruthy();
|
||||
const myObj = { Name: 'Adam', sUrnAME: 'Smith' };
|
||||
const myObjLower = lowercaseKeys(myObj);
|
||||
expect(myObjLower).toEqual({name: 'Adam', surname: 'Smith'});
|
||||
expect(myObj).toEqual({ Name: 'Adam', sUrnAME: 'Smith' });
|
||||
});
|
||||
11
test4/luhnCheck/luhnCheck.js
Normal file
11
test4/luhnCheck/luhnCheck.js
Normal file
@ -0,0 +1,11 @@
|
||||
const luhnCheck = num => {
|
||||
let arr = (num + '')
|
||||
.split('')
|
||||
.reverse()
|
||||
.map(x => parseInt(x));
|
||||
let lastDigit = arr.splice(0, 1)[0];
|
||||
let sum = arr.reduce((acc, val, i) => (i % 2 !== 0 ? acc + val : acc + (val * 2) % 9 || 9), 0);
|
||||
sum += lastDigit;
|
||||
return sum % 10 === 0;
|
||||
};
|
||||
module.exports = luhnCheck;
|
||||
11
test4/luhnCheck/luhnCheck.test.js
Normal file
11
test4/luhnCheck/luhnCheck.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const luhnCheck = require('./luhnCheck.js');
|
||||
|
||||
test('Testing luhnCheck', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof luhnCheck === 'function').toBeTruthy();
|
||||
expect(luhnCheck(6011329933655299)).toBe(false);
|
||||
expect(luhnCheck('4485275742308327')).toBe(true);
|
||||
expect(luhnCheck(123456789)).toBe(false);
|
||||
});
|
||||
6
test4/mapKeys/mapKeys.js
Normal file
6
test4/mapKeys/mapKeys.js
Normal file
@ -0,0 +1,6 @@
|
||||
const mapKeys = (obj, fn) =>
|
||||
Object.keys(obj).reduce((acc, k) => {
|
||||
acc[fn(obj[k], k, obj)] = obj[k];
|
||||
return acc;
|
||||
}, {});
|
||||
module.exports = mapKeys;
|
||||
9
test4/mapKeys/mapKeys.test.js
Normal file
9
test4/mapKeys/mapKeys.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const mapKeys = require('./mapKeys.js');
|
||||
|
||||
test('Testing mapKeys', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof mapKeys === 'function').toBeTruthy();
|
||||
expect(mapKeys({ a: 1, b: 2 }, (val, key) => key + val)).toEqual({ a1: 1, b2: 2 });
|
||||
});
|
||||
5
test4/mapObject/mapObject.js
Normal file
5
test4/mapObject/mapObject.js
Normal file
@ -0,0 +1,5 @@
|
||||
const mapObject = (arr, fn) =>
|
||||
(a => (
|
||||
(a = [arr, arr.map(fn)]), a[0].reduce((acc, val, ind) => ((acc[val] = a[1][ind]), acc), {})
|
||||
))();
|
||||
module.exports = mapObject;
|
||||
11
test4/mapObject/mapObject.test.js
Normal file
11
test4/mapObject/mapObject.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const mapObject = require('./mapObject.js');
|
||||
|
||||
test('Testing mapObject', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof mapObject === 'function').toBeTruthy();
|
||||
expect(mapObject([1, 2, 3], a => a * a)).toEqual({ 1: 1, 2: 4, 3: 9 });
|
||||
expect(mapObject([1, 2, 3, 4], (a, b) => b - a)).toEqual({ 1: -1, 2: -1, 3: -1, 4: -1 });
|
||||
expect(mapObject([1, 2, 3, 4], (a, b) => a - b)).toEqual({ 1: 1, 2: 1, 3: 1, 4: 1 });
|
||||
});
|
||||
6
test4/mapValues/mapValues.js
Normal file
6
test4/mapValues/mapValues.js
Normal file
@ -0,0 +1,6 @@
|
||||
const mapValues = (obj, fn) =>
|
||||
Object.keys(obj).reduce((acc, k) => {
|
||||
acc[k] = fn(obj[k], k, obj);
|
||||
return acc;
|
||||
}, {});
|
||||
module.exports = mapValues;
|
||||
13
test4/mapValues/mapValues.test.js
Normal file
13
test4/mapValues/mapValues.test.js
Normal file
@ -0,0 +1,13 @@
|
||||
const expect = require('expect');
|
||||
const mapValues = require('./mapValues.js');
|
||||
|
||||
test('Testing mapValues', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof mapValues === 'function').toBeTruthy();
|
||||
const users = {
|
||||
fred: { user: 'fred', age: 40 },
|
||||
pebbles: { user: 'pebbles', age: 1 }
|
||||
};
|
||||
expect(mapValues(users, u => u.age)).toEqual({ fred: 40, pebbles: 1 });
|
||||
});
|
||||
3
test4/mask/mask.js
Normal file
3
test4/mask/mask.js
Normal file
@ -0,0 +1,3 @@
|
||||
const mask = (cc, num = 4, mask = '*') =>
|
||||
('' + cc).slice(0, -num).replace(/./g, mask) + ('' + cc).slice(-num);
|
||||
module.exports = mask;
|
||||
11
test4/mask/mask.test.js
Normal file
11
test4/mask/mask.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const mask = require('./mask.js');
|
||||
|
||||
test('Testing mask', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof mask === 'function').toBeTruthy();
|
||||
expect(mask(1234567890)).toBe('******7890');
|
||||
expect(mask(1234567890, 3)).toBe('*******890');
|
||||
expect(mask(1234567890, -4, '$')).toBe('$$$$567890');
|
||||
});
|
||||
3
test4/matches/matches.js
Normal file
3
test4/matches/matches.js
Normal file
@ -0,0 +1,3 @@
|
||||
const matches = (obj, source) =>
|
||||
Object.keys(source).every(key => obj.hasOwnProperty(key) && obj[key] === source[key]);
|
||||
module.exports = matches;
|
||||
14
test4/matches/matches.test.js
Normal file
14
test4/matches/matches.test.js
Normal file
@ -0,0 +1,14 @@
|
||||
const expect = require('expect');
|
||||
const matches = require('./matches.js');
|
||||
|
||||
test('Testing matches', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof matches === 'function').toBeTruthy();
|
||||
expect(
|
||||
matches({ age: 25, hair: 'long', beard: true }, { hair: 'long', beard: true })
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
matches({ hair: 'long', beard: true }, { age: 25, hair: 'long', beard: true })
|
||||
).toBeFalsy();
|
||||
});
|
||||
8
test4/matchesWith/matchesWith.js
Normal file
8
test4/matchesWith/matchesWith.js
Normal file
@ -0,0 +1,8 @@
|
||||
const matchesWith = (obj, source, fn) =>
|
||||
Object.keys(source).every(
|
||||
key =>
|
||||
obj.hasOwnProperty(key) && fn
|
||||
? fn(obj[key], source[key], key, obj, source)
|
||||
: obj[key] == source[key]
|
||||
);
|
||||
module.exports = matchesWith;
|
||||
14
test4/matchesWith/matchesWith.test.js
Normal file
14
test4/matchesWith/matchesWith.test.js
Normal file
@ -0,0 +1,14 @@
|
||||
const expect = require('expect');
|
||||
const matchesWith = require('./matchesWith.js');
|
||||
|
||||
test('Testing matchesWith', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof matchesWith === 'function').toBeTruthy();
|
||||
const isGreeting = val => /^h(?:i|ello)$/.test(val);
|
||||
expect(matchesWith(
|
||||
{ greeting: 'hello' },
|
||||
{ greeting: 'hi' },
|
||||
(oV, sV) => isGreeting(oV) && isGreeting(sV)
|
||||
)).toBeTruthy();
|
||||
});
|
||||
2
test4/maxBy/maxBy.js
Normal file
2
test4/maxBy/maxBy.js
Normal file
@ -0,0 +1,2 @@
|
||||
const maxBy = (arr, fn) => Math.max(...arr.map(typeof fn === 'function' ? fn : val => val[fn]));
|
||||
module.exports = maxBy;
|
||||
10
test4/maxBy/maxBy.test.js
Normal file
10
test4/maxBy/maxBy.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const maxBy = require('./maxBy.js');
|
||||
|
||||
test('Testing maxBy', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof maxBy === 'function').toBeTruthy();
|
||||
expect(maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n)).toBe(8);
|
||||
expect(maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n')).toBe(8);
|
||||
});
|
||||
2
test4/maxN/maxN.js
Normal file
2
test4/maxN/maxN.js
Normal file
@ -0,0 +1,2 @@
|
||||
const maxN = (arr, n = 1) => [...arr].sort((a, b) => b - a).slice(0, n);
|
||||
module.exports = maxN;
|
||||
10
test4/maxN/maxN.test.js
Normal file
10
test4/maxN/maxN.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const maxN = require('./maxN.js');
|
||||
|
||||
test('Testing maxN', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof maxN === 'function').toBeTruthy();
|
||||
expect(maxN([1, 2, 3])).toEqual([3]);
|
||||
expect(maxN([1, 2, 3], 2)).toEqual([3, 2]);
|
||||
});
|
||||
6
test4/median/median.js
Normal file
6
test4/median/median.js
Normal file
@ -0,0 +1,6 @@
|
||||
const median = arr => {
|
||||
const mid = Math.floor(arr.length / 2),
|
||||
nums = [...arr].sort((a, b) => a - b);
|
||||
return arr.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
|
||||
};
|
||||
module.exports = median;
|
||||
10
test4/median/median.test.js
Normal file
10
test4/median/median.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const median = require('./median.js');
|
||||
|
||||
test('Testing median', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof median === 'function').toBeTruthy();
|
||||
expect(median([5, 6, 50, 1, -5])).toBe(5);
|
||||
expect(median([1, 2, 3])).toBe(2);
|
||||
});
|
||||
9
test4/memoize/memoize.js
Normal file
9
test4/memoize/memoize.js
Normal file
@ -0,0 +1,9 @@
|
||||
const memoize = fn => {
|
||||
const cache = new Map();
|
||||
const cached = function(val) {
|
||||
return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val);
|
||||
};
|
||||
cached.cache = cache;
|
||||
return cached;
|
||||
};
|
||||
module.exports = memoize;
|
||||
13
test4/memoize/memoize.test.js
Normal file
13
test4/memoize/memoize.test.js
Normal file
@ -0,0 +1,13 @@
|
||||
const expect = require('expect');
|
||||
const memoize = require('./memoize.js');
|
||||
|
||||
test('Testing memoize', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof memoize === 'function').toBeTruthy();
|
||||
const f = x => x * x;
|
||||
const square = memoize(f);
|
||||
expect(square(2)).toBe(4);
|
||||
expect(square(3)).toBe(9);
|
||||
expect(Array.from(square.cache)).toEqual([[2,4],[3,9]]);
|
||||
});
|
||||
10
test4/merge/merge.js
Normal file
10
test4/merge/merge.js
Normal file
@ -0,0 +1,10 @@
|
||||
const merge = (...objs) =>
|
||||
[...objs].reduce(
|
||||
(acc, obj) =>
|
||||
Object.keys(obj).reduce((a, k) => {
|
||||
acc[k] = acc.hasOwnProperty(k) ? [].concat(acc[k]).concat(obj[k]) : obj[k];
|
||||
return acc;
|
||||
}, {}),
|
||||
{}
|
||||
);
|
||||
module.exports = merge;
|
||||
18
test4/merge/merge.test.js
Normal file
18
test4/merge/merge.test.js
Normal file
@ -0,0 +1,18 @@
|
||||
const expect = require('expect');
|
||||
const merge = require('./merge.js');
|
||||
|
||||
test('Testing merge', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof merge === 'function').toBeTruthy();
|
||||
const object = {
|
||||
a: [{ x: 2 }, { y: 4 }],
|
||||
b: 1
|
||||
};
|
||||
const other = {
|
||||
a: { z: 3 },
|
||||
b: [2, 3],
|
||||
c: 'foo'
|
||||
};
|
||||
expect(merge(object, other)).toEqual({ a: [ { x: 2 }, { y: 4 }, { z: 3 } ], b: [ 1, 2, 3 ], c: 'foo' });
|
||||
});
|
||||
2
test4/minBy/minBy.js
Normal file
2
test4/minBy/minBy.js
Normal file
@ -0,0 +1,2 @@
|
||||
const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : val => val[fn]));
|
||||
module.exports = minBy;
|
||||
10
test4/minBy/minBy.test.js
Normal file
10
test4/minBy/minBy.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const minBy = require('./minBy.js');
|
||||
|
||||
test('Testing minBy', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof minBy === 'function').toBeTruthy();
|
||||
expect(minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n)).toBe(2);
|
||||
expect(minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n')).toBe(2);
|
||||
});
|
||||
2
test4/minN/minN.js
Normal file
2
test4/minN/minN.js
Normal file
@ -0,0 +1,2 @@
|
||||
const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n);
|
||||
module.exports = minN;
|
||||
10
test4/minN/minN.test.js
Normal file
10
test4/minN/minN.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const minN = require('./minN.js');
|
||||
|
||||
test('Testing minN', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof minN === 'function').toBeTruthy();
|
||||
expect(minN([1, 2, 3])).toEqual([1]);
|
||||
expect(minN([1, 2, 3], 2)).toEqual([1, 2]);
|
||||
});
|
||||
9
test4/mostPerformant/mostPerformant.js
Normal file
9
test4/mostPerformant/mostPerformant.js
Normal file
@ -0,0 +1,9 @@
|
||||
const mostPerformant = (fns, iterations = 10000) => {
|
||||
const times = fns.map(fn => {
|
||||
const before = performance.now();
|
||||
for (let i = 0; i < iterations; i++) fn();
|
||||
return performance.now() - before;
|
||||
});
|
||||
return times.indexOf(Math.min(...times));
|
||||
};
|
||||
module.exports = mostPerformant;
|
||||
8
test4/mostPerformant/mostPerformant.test.js
Normal file
8
test4/mostPerformant/mostPerformant.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const mostPerformant = require('./mostPerformant.js');
|
||||
|
||||
test('Testing mostPerformant', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof mostPerformant === 'function').toBeTruthy();
|
||||
});
|
||||
2
test4/negate/negate.js
Normal file
2
test4/negate/negate.js
Normal file
@ -0,0 +1,2 @@
|
||||
const negate = func => (...args) => !func(...args);
|
||||
module.exports = negate;
|
||||
9
test4/negate/negate.test.js
Normal file
9
test4/negate/negate.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const negate = require('./negate.js');
|
||||
|
||||
test('Testing negate', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof negate === 'function').toBeTruthy();
|
||||
expect([1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 === 0))).toEqual([1, 3, 5]);
|
||||
});
|
||||
5
test4/nest/nest.js
Normal file
5
test4/nest/nest.js
Normal file
@ -0,0 +1,5 @@
|
||||
const nest = (items, id = null, link = 'parent_id') =>
|
||||
items
|
||||
.filter(item => item[link] === id)
|
||||
.map(item => ({ ...item, children: nest(items, item.id) }));
|
||||
module.exports = nest;
|
||||
8
test4/nest/nest.test.js
Normal file
8
test4/nest/nest.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const nest = require('./nest.js');
|
||||
|
||||
test('Testing nest', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof nest === 'function').toBeTruthy();
|
||||
});
|
||||
2
test4/nodeListToArray/nodeListToArray.js
Normal file
2
test4/nodeListToArray/nodeListToArray.js
Normal file
@ -0,0 +1,2 @@
|
||||
const nodeListToArray = nodeList => Array.prototype.slice.call(nodeList);
|
||||
module.exports = nodeListToArray;
|
||||
8
test4/nodeListToArray/nodeListToArray.test.js
Normal file
8
test4/nodeListToArray/nodeListToArray.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const nodeListToArray = require('./nodeListToArray.js');
|
||||
|
||||
test('Testing nodeListToArray', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof nodeListToArray === 'function').toBeTruthy();
|
||||
});
|
||||
2
test4/none/none.js
Normal file
2
test4/none/none.js
Normal file
@ -0,0 +1,2 @@
|
||||
const none = (arr, fn = Boolean) => !arr.some(fn);
|
||||
module.exports = none;
|
||||
12
test4/none/none.test.js
Normal file
12
test4/none/none.test.js
Normal file
@ -0,0 +1,12 @@
|
||||
const expect = require('expect');
|
||||
const none = require('./none.js');
|
||||
|
||||
test('Testing none', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof none === 'function').toBeTruthy();
|
||||
expect(none([0,undefined,NaN,null,''])).toBeTruthy();
|
||||
expect(none([0,1])).toBeFalsy();
|
||||
expect(none([4,1,0,3], x => x < 0)).toBeTruthy();
|
||||
expect(none([0,1,2], x => x === 1)).toBeFalsy();
|
||||
});
|
||||
2
test4/nthArg/nthArg.js
Normal file
2
test4/nthArg/nthArg.js
Normal file
@ -0,0 +1,2 @@
|
||||
const nthArg = n => (...args) => args.slice(n)[0];
|
||||
module.exports = nthArg;
|
||||
13
test4/nthArg/nthArg.test.js
Normal file
13
test4/nthArg/nthArg.test.js
Normal file
@ -0,0 +1,13 @@
|
||||
const expect = require('expect');
|
||||
const nthArg = require('./nthArg.js');
|
||||
|
||||
test('Testing nthArg', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof nthArg === 'function').toBeTruthy();
|
||||
const third = nthArg(2);
|
||||
expect(third(1, 2, 3)).toBe(3);
|
||||
expect(third(1, 2)).toBe(undefined);
|
||||
const last = nthArg(-1);
|
||||
expect(last(1, 2, 3, 4, 5)).toBe(5);
|
||||
});
|
||||
2
test4/nthElement/nthElement.js
Normal file
2
test4/nthElement/nthElement.js
Normal file
@ -0,0 +1,2 @@
|
||||
const nthElement = (arr, n = 0) => (n > 0 ? arr.slice(n, n + 1) : arr.slice(n))[0];
|
||||
module.exports = nthElement;
|
||||
10
test4/nthElement/nthElement.test.js
Normal file
10
test4/nthElement/nthElement.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const nthElement = require('./nthElement.js');
|
||||
|
||||
test('Testing nthElement', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof nthElement === 'function').toBeTruthy();
|
||||
expect(nthElement(['a', 'b', 'c'], 1)).toBe('b');
|
||||
expect(nthElement(['a', 'b', 'c'], -3)).toBe('a');
|
||||
});
|
||||
2
test4/objectFromPairs/objectFromPairs.js
Normal file
2
test4/objectFromPairs/objectFromPairs.js
Normal file
@ -0,0 +1,2 @@
|
||||
const objectFromPairs = arr => arr.reduce((a, v) => ((a[v[0]] = v[1]), a), {});
|
||||
module.exports = objectFromPairs;
|
||||
9
test4/objectFromPairs/objectFromPairs.test.js
Normal file
9
test4/objectFromPairs/objectFromPairs.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const objectFromPairs = require('./objectFromPairs.js');
|
||||
|
||||
test('Testing objectFromPairs', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof objectFromPairs === 'function').toBeTruthy();
|
||||
expect(objectFromPairs([['a', 1], ['b', 2]])).toEqual({a: 1, b: 2});
|
||||
});
|
||||
2
test4/objectToPairs/objectToPairs.js
Normal file
2
test4/objectToPairs/objectToPairs.js
Normal file
@ -0,0 +1,2 @@
|
||||
const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]);
|
||||
module.exports = objectToPairs;
|
||||
9
test4/objectToPairs/objectToPairs.test.js
Normal file
9
test4/objectToPairs/objectToPairs.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const objectToPairs = require('./objectToPairs.js');
|
||||
|
||||
test('Testing objectToPairs', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof objectToPairs === 'function').toBeTruthy();
|
||||
expect(objectToPairs({ a: 1, b: 2 })).toEqual([['a',1],['b',2]]);
|
||||
});
|
||||
19
test4/observeMutations/observeMutations.js
Normal file
19
test4/observeMutations/observeMutations.js
Normal file
@ -0,0 +1,19 @@
|
||||
const observeMutations = (element, callback, options) => {
|
||||
const observer = new MutationObserver(mutations => mutations.forEach(m => callback(m)));
|
||||
observer.observe(
|
||||
element,
|
||||
Object.assign(
|
||||
{
|
||||
childList: true,
|
||||
attributes: true,
|
||||
attributeOldValue: true,
|
||||
characterData: true,
|
||||
characterDataOldValue: true,
|
||||
subtree: true
|
||||
},
|
||||
options
|
||||
)
|
||||
);
|
||||
return observer;
|
||||
};
|
||||
module.exports = observeMutations;
|
||||
8
test4/observeMutations/observeMutations.test.js
Normal file
8
test4/observeMutations/observeMutations.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const observeMutations = require('./observeMutations.js');
|
||||
|
||||
test('Testing observeMutations', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof observeMutations === 'function').toBeTruthy();
|
||||
});
|
||||
2
test4/off/off.js
Normal file
2
test4/off/off.js
Normal file
@ -0,0 +1,2 @@
|
||||
const off = (el, evt, fn, opts = false) => el.removeEventListener(evt, fn, opts);
|
||||
module.exports = off;
|
||||
8
test4/off/off.test.js
Normal file
8
test4/off/off.test.js
Normal file
@ -0,0 +1,8 @@
|
||||
const expect = require('expect');
|
||||
const off = require('./off.js');
|
||||
|
||||
test('Testing off', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof off === 'function').toBeTruthy();
|
||||
});
|
||||
2
test4/offset/offset.js
Normal file
2
test4/offset/offset.js
Normal file
@ -0,0 +1,2 @@
|
||||
const offset = (arr, offset) => [...arr.slice(offset), ...arr.slice(0, offset)];
|
||||
module.exports = offset;
|
||||
14
test4/offset/offset.test.js
Normal file
14
test4/offset/offset.test.js
Normal file
@ -0,0 +1,14 @@
|
||||
const expect = require('expect');
|
||||
const offset = require('./offset.js');
|
||||
|
||||
test('Testing offset', () => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
expect(typeof offset === 'function').toBeTruthy();
|
||||
expect(offset([1, 2, 3, 4, 5], 0)).toEqual([1, 2, 3, 4, 5]);
|
||||
expect(offset([1, 2, 3, 4, 5], 2)).toEqual([3, 4, 5, 1, 2]);
|
||||
expect(offset([1, 2, 3, 4, 5], -2)).toEqual([4, 5, 1, 2, 3]);
|
||||
expect(offset([1, 2, 3, 4, 5], 6)).toEqual([1, 2, 3, 4, 5]);
|
||||
expect(offset([1, 2, 3, 4, 5], -6)).toEqual([1, 2, 3, 4, 5]);
|
||||
expect(offset([], 3)).toEqual([]);
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user