ran npm run tester -> logged invertKeyValues test are invalid

This commit is contained in:
King
2018-01-24 06:29:38 -05:00
parent d835cf4b40
commit 737acd870d
270 changed files with 1141 additions and 872 deletions

View File

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

View File

@ -1,4 +1,4 @@
const fs = require('fs');
const JSONToFile = (obj, filename) =>
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
module.exports = JSONToFile
module.exports = JSONToFile

View File

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

View File

@ -7,4 +7,4 @@ args
.replace(/\/(\?|&|#[^!])/g, '$1')
.replace(/\?/g, '&')
.replace('&', '?');
module.exports = URLJoin
module.exports = URLJoin

View File

@ -2,4 +2,4 @@ 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
module.exports = UUIDGeneratorBrowser

View File

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

View File

@ -8,4 +8,4 @@ acc.concat(anagrams(str.slice(0, i) + str.slice(i + 1)).map(val => letter + val)
[]
);
};
module.exports = anagrams
module.exports = anagrams

View File

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

View File

@ -1,2 +1,2 @@
const atob = str => new Buffer(str, 'base64').toString('binary');
module.exports = atob
module.exports = atob

View File

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

View File

@ -1,4 +1,4 @@
const averageBy = (arr, fn) =>
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0) /
arr.length;
module.exports = averageBy
module.exports = averageBy

View File

@ -5,4 +5,4 @@ if (arr[mid] > val) return binarySearch(arr, val, start, mid - 1);
if (arr[mid] < val) return binarySearch(arr, val, mid + 1, end);
return mid;
}
module.exports = binarySearch
module.exports = binarySearch

View File

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

View File

@ -1,2 +1,2 @@
const btoa = str => new Buffer(str, 'binary').toString('base64');
module.exports = btoa
module.exports = btoa

View File

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

View File

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

View File

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

View File

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

View File

@ -1,2 +1,2 @@
const castArray = val => (Array.isArray(val) ? val : [val]);
module.exports = castArray
module.exports = castArray

View File

@ -3,4 +3,4 @@ let curr = 0;
const next = () => fns[curr++](next);
next();
};
module.exports = chainAsync
module.exports = chainAsync

View File

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

View File

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

View File

@ -8,4 +8,4 @@ delete obj[key];
});
return obj;
};
module.exports = cleanObj
module.exports = cleanObj

View File

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

View File

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

View File

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

View File

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

View File

@ -1,2 +1,2 @@
const collectInto = fn => (...args) => fn(args);
module.exports = collectInto
module.exports = collectInto

View File

@ -16,4 +16,4 @@ bgMagenta: `\x1b[45m${args.join(' ')}\x1b[0m`,
bgCyan: `\x1b[46m${args.join(' ')}\x1b[0m`,
bgWhite: `\x1b[47m${args.join(' ')}\x1b[0m`
});
module.exports = colorize
module.exports = colorize

View File

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

View File

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

View File

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

View File

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

View File

@ -15,4 +15,4 @@ document.getSelection().removeAllRanges();
document.getSelection().addRange(selected);
}
};
module.exports = copyToClipboard
module.exports = copyToClipboard

View File

@ -3,4 +3,4 @@ arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val, i) =>
acc[val] = (acc[val] || 0) + 1;
return acc;
}, {});
module.exports = countBy
module.exports = countBy

View File

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

View File

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

View File

@ -3,4 +3,4 @@ const el = document.createElement('div');
el.innerHTML = str;
return el.firstElementChild;
};
module.exports = createElement
module.exports = createElement

View File

@ -12,4 +12,4 @@ const i = (this.hub[event] || []).findIndex(h => h === handler);
if (i > -1) this.hub[event].splice(i, 1);
}
});
module.exports = createEventHub
module.exports = createEventHub

View File

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

View File

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

View File

@ -1,3 +1,3 @@
const decapitalize = ([first, ...rest], upperRest = false) =>
first.toLowerCase() + (upperRest ? rest.join('').toUpperCase() : rest.join(''));
module.exports = decapitalize
module.exports = decapitalize

View File

@ -5,4 +5,4 @@ key => (clone[key] = typeof obj[key] === 'object' ? deepClone(obj[key]) : obj[ke
);
return clone;
};
module.exports = deepClone
module.exports = deepClone

View File

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

View File

@ -1,2 +1,2 @@
const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj);
module.exports = defaults
module.exports = defaults

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,4 +6,4 @@ return partiallyVisible
((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth))
: top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
};
module.exports = elementIsVisibleInViewport
module.exports = elementIsVisibleInViewport

View File

@ -16,4 +16,4 @@ j++;
}
return ratings;
};
module.exports = elo
module.exports = elo

View File

@ -8,4 +8,4 @@ let keys = Object.keys(a);
if (keys.length !== Object.keys(b).length) return false;
return keys.every(k => equals(a[k], b[k]));
};
module.exports = equals
module.exports = equals

View File

@ -10,4 +10,4 @@ tag =>
'"': '&quot;'
}[tag] || tag)
);
module.exports = escapeHTML
module.exports = escapeHTML

View File

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

View File

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

View File

@ -5,4 +5,4 @@ shortHex
.split('')
.map(x => x + x)
.join('');
module.exports = extendHex
module.exports = extendHex

View File

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

View File

@ -17,4 +17,4 @@ return acc;
}, []);
return primes ? array.filter(isPrime) : array;
};
module.exports = factors
module.exports = factors

View File

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

View File

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

View File

@ -5,4 +5,4 @@ return Array.from({ length: n }).reduce(
[]
);
};
module.exports = fibonacciUntilNum
module.exports = fibonacciUntilNum

View File

@ -1,2 +1,2 @@
const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i));
module.exports = filterNonUnique
module.exports = filterNonUnique

View File

@ -1,2 +1,2 @@
const findKey = (obj, fn) => Object.keys(obj).find(key => fn(obj[key], key, obj));
module.exports = findKey
module.exports = findKey

View File

@ -1,2 +1,2 @@
const findLast = (arr, fn) => arr.filter(fn).slice(-1);
module.exports = findLast
const findLast = (arr, fn) => arr.filter(fn).slice(-1)[0];
module.exports = findLast

View File

@ -0,0 +1,6 @@
const findLastIndex = (arr, fn) =>
arr
.map((val, i) => [i, val])
.filter(val => fn(val[1], val[0], arr))
.slice(-1)[0][0];
module.exports = findLastIndex

View File

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

View File

@ -2,4 +2,4 @@ const findLastKey = (obj, fn) =>
Object.keys(obj)
.reverse()
.find(key => fn(obj[key], key, obj));
module.exports = findLastKey
module.exports = findLastKey

View File

@ -2,4 +2,4 @@ const flatten = (arr, depth = 1) =>
depth != 1
? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flatten(v, depth - 1) : v), [])
: arr.reduce((a, v) => a.concat(v), []);
module.exports = flatten
module.exports = flatten

View File

@ -1,2 +1,2 @@
const flip = fn => (first, ...rest) => fn(...rest, first);
module.exports = flip
module.exports = flip

View File

@ -3,4 +3,4 @@ arr
.slice(0)
.reverse()
.forEach(callback);
module.exports = forEachRight
module.exports = forEachRight

View File

@ -1,2 +1,2 @@
const forOwn = (obj, fn) => Object.keys(obj).forEach(key => fn(obj[key], key, obj));
module.exports = forOwn
module.exports = forOwn

View File

@ -2,4 +2,4 @@ const forOwnRight = (obj, fn) =>
Object.keys(obj)
.reverse()
.forEach(key => fn(obj[key], key, obj));
module.exports = forOwnRight
module.exports = forOwnRight

View File

@ -12,4 +12,4 @@ return Object.entries(time)
.map(val => val[1] + ' ' + (val[1] !== 1 ? val[0] + 's' : val[0]))
.join(', ');
};
module.exports = formatDuration
module.exports = formatDuration

View File

@ -3,4 +3,4 @@ str
.replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2')
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + separator + '$2')
.toLowerCase();
module.exports = fromCamelCase
module.exports = fromCamelCase

View File

@ -1,2 +1,2 @@
const functionName = fn => (console.debug(fn.name), fn);
module.exports = functionName
module.exports = functionName

View File

@ -3,4 +3,4 @@ const functions = (obj, inherited = false) =>
? [...Object.keys(obj), ...Object.keys(Object.getPrototypeOf(obj))]
: Object.keys(obj)
).filter(key => typeof obj[key] === 'function');
module.exports = functions
module.exports = functions

View File

@ -2,4 +2,4 @@ const gcd = (...arr) => {
const _gcd = (x, y) => (!y ? x : gcd(y, x % y));
return [...arr].reduce((a, b) => _gcd(a, b));
};
module.exports = gcd
module.exports = gcd

View File

@ -2,4 +2,4 @@ const geometricProgression = (end, start = 1, step = 2) =>
Array.from({ length: Math.floor(Math.log(end / start) / Math.log(step)) + 1 }).map(
(v, i) => start * step ** i
);
module.exports = geometricProgression
module.exports = geometricProgression

View File

@ -6,4 +6,4 @@ s
.filter(t => t !== '')
.reduce((prev, cur) => prev && prev[cur], from)
);
module.exports = get
module.exports = get

View File

@ -1,3 +1,3 @@
const getDaysDiffBetweenDates = (dateInitial, dateFinal) =>
(dateFinal - dateInitial) / (1000 * 3600 * 24);
module.exports = getDaysDiffBetweenDates
module.exports = getDaysDiffBetweenDates

View File

@ -2,4 +2,4 @@ const getScrollPosition = (el = window) => ({
x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft,
y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop
});
module.exports = getScrollPosition
module.exports = getScrollPosition

View File

@ -1,2 +1,2 @@
const getStyle = (el, ruleName) => getComputedStyle(el)[ruleName];
module.exports = getStyle
module.exports = getStyle

View File

@ -1,3 +1,3 @@
const getType = v =>
v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase();
module.exports = getType
module.exports = getType

View File

@ -2,4 +2,4 @@ const getURLParameters = url =>
url
.match(/([^?=&]+)(=([^&]*))/g)
.reduce((a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a), {});
module.exports = getURLParameters
module.exports = getURLParameters

View File

@ -3,4 +3,4 @@ arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val, i) =>
acc[val] = (acc[val] || []).concat(arr[i]);
return acc;
}, {});
module.exports = groupBy
module.exports = groupBy

View File

@ -1,2 +1,2 @@
const hammingDistance = (num1, num2) => ((num1 ^ num2).toString(2).match(/1/g) || '').length;
module.exports = hammingDistance
module.exports = hammingDistance

View File

@ -1,2 +1,2 @@
const hasClass = (el, className) => el.classList.contains(className);
module.exports = hasClass
module.exports = hasClass

View File

@ -1,3 +1,3 @@
const hasFlags = (...flags) =>
flags.every(flag => process.argv.includes(/^-{1,2}/.test(flag) ? flag : '--' + flag));
module.exports = hasFlags
module.exports = hasFlags

View File

@ -6,4 +6,4 @@ for (let i = 0; i < view.byteLength; i += 4)
hexes.push(('00000000' + view.getUint32(i).toString(16)).slice(-8));
return hexes.join('');
});
module.exports = hashBrowser
module.exports = hashBrowser

View File

@ -12,4 +12,4 @@ crypto
0
)
);
module.exports = hashNode
module.exports = hashNode

View File

@ -1,2 +1,2 @@
const head = arr => arr[0];
module.exports = head
module.exports = head

View File

@ -17,4 +17,4 @@ return (
')'
);
};
module.exports = hexToRGB
module.exports = hexToRGB

View File

@ -1,2 +1,2 @@
const hide = (...el) => [...el].forEach(e => (e.style.display = 'none'));
module.exports = hide
module.exports = hide

View File

@ -8,4 +8,4 @@ num = num / divisor;
}
return i;
};
module.exports = howManyTimes
module.exports = howManyTimes

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