|
|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
const fs = typeof require !== "undefined" && require('fs');
|
|
|
|
|
const crypto = typeof require !== "undefined" && require('crypto');
|
|
|
|
|
const fs = typeof require !== 'undefined' && require('fs');
|
|
|
|
|
const crypto = typeof require !== 'undefined' && require('crypto');
|
|
|
|
|
|
|
|
|
|
const CSVToArray = (data, delimiter = ',', omitFirstRow = false) =>
|
|
|
|
|
data
|
|
|
|
|
@ -963,9 +963,9 @@ const reject = (pred, array) => array.filter((...args) => !pred(...args));
|
|
|
|
|
const remove = (arr, func) =>
|
|
|
|
|
Array.isArray(arr)
|
|
|
|
|
? arr.filter(func).reduce((acc, val) => {
|
|
|
|
|
arr.splice(arr.indexOf(val), 1);
|
|
|
|
|
return acc.concat(val);
|
|
|
|
|
}, [])
|
|
|
|
|
arr.splice(arr.indexOf(val), 1);
|
|
|
|
|
return acc.concat(val);
|
|
|
|
|
}, [])
|
|
|
|
|
: [];
|
|
|
|
|
const removeNonASCII = str => str.replace(/[^\x20-\x7E]/g, '');
|
|
|
|
|
const renameKeys = (keysMap, obj) =>
|
|
|
|
|
@ -1337,11 +1337,11 @@ const binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
|
|
|
|
|
const celsiusToFahrenheit = degrees => 1.8 * degrees + 32;
|
|
|
|
|
const cleanObj = (obj, keysToKeep = [], childIndicator) => {
|
|
|
|
|
Object.keys(obj).forEach(key => {
|
|
|
|
|
if (key === childIndicator) {
|
|
|
|
|
if (key === childIndicator)
|
|
|
|
|
cleanObj(obj[key], keysToKeep, childIndicator);
|
|
|
|
|
} else if (!keysToKeep.includes(key)) {
|
|
|
|
|
else if (!keysToKeep.includes(key))
|
|
|
|
|
delete obj[key];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
return obj;
|
|
|
|
|
};
|
|
|
|
|
@ -1358,15 +1358,16 @@ const factors = (num, primes = false) => {
|
|
|
|
|
let array = Array.from({ length: num - 1 })
|
|
|
|
|
.map((val, i) => (num % (i + 2) === 0 ? i + 2 : false))
|
|
|
|
|
.filter(val => val);
|
|
|
|
|
if (isNeg)
|
|
|
|
|
if (isNeg) {
|
|
|
|
|
array = array.reduce((acc, val) => {
|
|
|
|
|
acc.push(val);
|
|
|
|
|
acc.push(-val);
|
|
|
|
|
return acc;
|
|
|
|
|
}, []);
|
|
|
|
|
}
|
|
|
|
|
return primes ? array.filter(isPrime) : array;
|
|
|
|
|
};
|
|
|
|
|
const fahrenheitToCelsius = degrees => (degrees - 32) * 5/9;
|
|
|
|
|
const fahrenheitToCelsius = degrees => (degrees - 32) * 5 / 9;
|
|
|
|
|
const fibonacciCountUntilNum = num =>
|
|
|
|
|
Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));
|
|
|
|
|
const fibonacciUntilNum = num => {
|
|
|
|
|
@ -1377,9 +1378,9 @@ const fibonacciUntilNum = num => {
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
const heronArea = (side_a, side_b, side_c) => {
|
|
|
|
|
const p = (side_a + side_b + side_c) / 2
|
|
|
|
|
return Math.sqrt(p * (p-side_a) * (p-side_b) * (p-side_c))
|
|
|
|
|
};
|
|
|
|
|
const p = (side_a + side_b + side_c) / 2;
|
|
|
|
|
return Math.sqrt(p * (p - side_a) * (p - side_b) * (p - side_c));
|
|
|
|
|
};
|
|
|
|
|
const howManyTimes = (num, divisor) => {
|
|
|
|
|
if (divisor === 1 || divisor === -1) return Infinity;
|
|
|
|
|
if (divisor === 0) return 0;
|
|
|
|
|
@ -1399,8 +1400,8 @@ const httpDelete = (url, callback, err = console.error) => {
|
|
|
|
|
};
|
|
|
|
|
const httpPut = (url, data, callback, err = console.error) => {
|
|
|
|
|
const request = new XMLHttpRequest();
|
|
|
|
|
request.open("PUT", url, true);
|
|
|
|
|
request.setRequestHeader('Content-type','application/json; charset=utf-8');
|
|
|
|
|
request.open('PUT', url, true);
|
|
|
|
|
request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
|
|
|
|
|
request.onload = () => callback(request);
|
|
|
|
|
request.onerror = () => err(request);
|
|
|
|
|
request.send(data);
|
|
|
|
|
@ -1411,13 +1412,13 @@ const isArmstrongNumber = digits =>
|
|
|
|
|
);
|
|
|
|
|
const isSimilar = (pattern, str) =>
|
|
|
|
|
[...str].reduce(
|
|
|
|
|
(matchIndex, char) =>
|
|
|
|
|
char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()
|
|
|
|
|
? matchIndex + 1
|
|
|
|
|
: matchIndex,
|
|
|
|
|
0
|
|
|
|
|
(matchIndex, char) =>
|
|
|
|
|
char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()
|
|
|
|
|
? matchIndex + 1
|
|
|
|
|
: matchIndex,
|
|
|
|
|
0
|
|
|
|
|
) === pattern.length;
|
|
|
|
|
const kmphToMph = (kmph) => 0.621371192 * kmph;
|
|
|
|
|
const kmphToMph = kmph => 0.621371192 * kmph;
|
|
|
|
|
const levenshteinDistance = (string1, string2) => {
|
|
|
|
|
if (string1.length === 0) return string2.length;
|
|
|
|
|
if (string2.length === 0) return string1.length;
|
|
|
|
|
@ -1429,9 +1430,9 @@ const levenshteinDistance = (string1, string2) => {
|
|
|
|
|
.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]) {
|
|
|
|
|
if (string2[i - 1] === string1[j - 1])
|
|
|
|
|
matrix[i][j] = matrix[i - 1][j - 1];
|
|
|
|
|
} else {
|
|
|
|
|
else {
|
|
|
|
|
matrix[i][j] = Math.min(
|
|
|
|
|
matrix[i - 1][j - 1] + 1,
|
|
|
|
|
matrix[i][j - 1] + 1,
|
|
|
|
|
@ -1442,16 +1443,16 @@ const levenshteinDistance = (string1, string2) => {
|
|
|
|
|
}
|
|
|
|
|
return matrix[string2.length][string1.length];
|
|
|
|
|
};
|
|
|
|
|
const mphToKmph = (mph) => 1.6093440006146922 * mph;
|
|
|
|
|
const mphToKmph = mph => 1.6093440006146922 * mph;
|
|
|
|
|
const pipeLog = data => console.log(data) || data;
|
|
|
|
|
const quickSort = ([n, ...nums], desc) =>
|
|
|
|
|
isNaN(n)
|
|
|
|
|
? []
|
|
|
|
|
: [
|
|
|
|
|
...quickSort(nums.filter(v => (desc ? v > n : v <= n)), desc),
|
|
|
|
|
n,
|
|
|
|
|
...quickSort(nums.filter(v => (!desc ? v > n : v <= n)), desc)
|
|
|
|
|
];
|
|
|
|
|
...quickSort(nums.filter(v => (desc ? v > n : v <= n)), desc),
|
|
|
|
|
n,
|
|
|
|
|
...quickSort(nums.filter(v => (!desc ? v > n : v <= n)), desc)
|
|
|
|
|
];
|
|
|
|
|
const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi, repl);
|
|
|
|
|
const solveRPN = rpn => {
|
|
|
|
|
const OPERATORS = {
|
|
|
|
|
@ -1469,14 +1470,14 @@ const solveRPN = rpn => {
|
|
|
|
|
.filter(el => !/\s+/.test(el) && el !== '')
|
|
|
|
|
];
|
|
|
|
|
solve.forEach(symbol => {
|
|
|
|
|
if (!isNaN(parseFloat(symbol)) && isFinite(symbol)) {
|
|
|
|
|
if (!isNaN(parseFloat(symbol)) && isFinite(symbol))
|
|
|
|
|
stack.push(symbol);
|
|
|
|
|
} else if (Object.keys(OPERATORS).includes(symbol)) {
|
|
|
|
|
else if (Object.keys(OPERATORS).includes(symbol)) {
|
|
|
|
|
const [a, b] = [stack.pop(), stack.pop()];
|
|
|
|
|
stack.push(OPERATORS[symbol](parseFloat(b), parseFloat(a)));
|
|
|
|
|
} else {
|
|
|
|
|
} 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`;
|
|
|
|
|
@ -1489,4 +1490,4 @@ const speechSynthesis = message => {
|
|
|
|
|
const squareSum = (...args) => args.reduce((squareSum, number) => squareSum + Math.pow(number, 2), 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {CSVToArray,CSVToJSON,JSONToFile,JSONtoCSV,RGBToHex,URLJoin,UUIDGeneratorBrowser,UUIDGeneratorNode,all,allEqual,any,approximatelyEqual,arrayToCSV,arrayToHtmlList,ary,atob,attempt,average,averageBy,bifurcate,bifurcateBy,bind,bindAll,bindKey,binomialCoefficient,bottomVisible,btoa,byteSize,call,capitalize,capitalizeEveryWord,castArray,chainAsync,chunk,clampNumber,cloneRegExp,coalesce,coalesceFactory,collectInto,colorize,compact,compose,composeRight,converge,copyToClipboard,countBy,countOccurrences,counter,createElement,createEventHub,currentURL,curry,dayOfYear,debounce,decapitalize,deepClone,deepFlatten,deepFreeze,defaults,defer,degreesToRads,delay,detectDeviceType,difference,differenceBy,differenceWith,dig,digitize,distance,drop,dropRight,dropRightWhile,dropWhile,elementContains,elementIsVisibleInViewport,elo,equals,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,filterNonUnique,filterNonUniqueBy,findKey,findLast,findLastIndex,findLastKey,flatten,flattenObject,flip,forEachRight,forOwn,forOwnRight,formatDuration,fromCamelCase,functionName,functions,gcd,geometricProgression,get,getColonTimeFromDate,getDaysDiffBetweenDates,getImages,getMeridiemSuffixOfInteger,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,hasFlags,hashBrowser,hashNode,head,hexToRGB,hide,httpGet,httpPost,httpsRedirect,hz,inRange,indentString,indexOfAll,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithRangeRight,initializeArrayWithValues,initializeNDArray,insertAfter,insertBefore,intersection,intersectionBy,intersectionWith,invertKeyValues,is,isAbsoluteURL,isAfterDate,isAnagram,isArrayLike,isBeforeDate,isBoolean,isBrowser,isBrowserTabFocused,isDivisible,isDuplexStream,isEmpty,isEven,isFunction,isLowerCase,isNil,isNull,isNumber,isObject,isObjectLike,isPlainObject,isPrime,isPrimitive,isPromiseLike,isReadableStream,isSameDate,isSorted,isStream,isString,isSymbol,isTravisCI,isUndefined,isUpperCase,isValidJSON,isWritableStream,join,last,lcm,longestItem,lowercaseKeys,luhnCheck,mapKeys,mapObject,mapString,mapValues,mask,matches,matchesWith,maxBy,maxDate,maxN,median,memoize,merge,minBy,minDate,minN,mostPerformant,negate,nest,nodeListToArray,none,nthArg,nthElement,objectFromPairs,objectToPairs,observeMutations,off,offset,omit,omitBy,on,onUserInputChange,once,orderBy,over,overArgs,pad,palindrome,parseCookie,partial,partialRight,partition,percentile,permutations,pick,pickBy,pipeAsyncFunctions,pipeFunctions,pluralize,powerset,prefix,prettyBytes,primes,promisify,pull,pullAtIndex,pullAtValue,pullBy,radsToDegrees,randomHexColorCode,randomIntArrayInRange,randomIntegerInRange,randomNumberInRange,readFileLines,rearg,recordAnimationFrames,redirect,reduceSuccessive,reduceWhich,reducedFilter,reject,remove,removeNonASCII,renameKeys,reverseString,round,runAsync,runPromisesInSeries,sample,sampleSize,scrollToTop,sdbm,serializeCookie,setStyle,shallowClone,shank,show,shuffle,similarity,size,sleep,smoothScroll,sortCharactersInString,sortedIndex,sortedIndexBy,sortedLastIndex,sortedLastIndexBy,splitLines,spreadOver,stableSort,standardDeviation,stringPermutations,stripHTMLTags,sum,sumBy,sumPower,symmetricDifference,symmetricDifferenceBy,symmetricDifferenceWith,tail,take,takeRight,takeRightWhile,takeWhile,throttle,timeTaken,times,toCamelCase,toCurrency,toDecimalMark,toHash,toKebabCase,toOrdinalSuffix,toSafeInteger,toSnakeCase,toTitleCase,toggleClass,tomorrow,transform,triggerEvent,truncateString,truthCheckCollection,unary,uncurry,unescapeHTML,unflattenObject,unfold,union,unionBy,unionWith,uniqueElements,uniqueElementsBy,uniqueElementsByRight,uniqueSymmetricDifference,untildify,unzip,unzipWith,validateNumber,when,without,words,xProd,yesNo,zip,zipObject,zipWith,JSONToDate,binarySearch,celsiusToFahrenheit,cleanObj,collatz,countVowels,factors,fahrenheitToCelsius,fibonacciCountUntilNum,fibonacciUntilNum,heronArea,howManyTimes,httpDelete,httpPut,isArmstrongNumber,isSimilar,kmphToMph,levenshteinDistance,mphToKmph,pipeLog,quickSort,removeVowels,solveRPN,speechSynthesis,squareSum}
|
|
|
|
|
module.exports = {CSVToArray, CSVToJSON, JSONToFile, JSONtoCSV, RGBToHex, URLJoin, UUIDGeneratorBrowser, UUIDGeneratorNode, all, allEqual, any, approximatelyEqual, arrayToCSV, arrayToHtmlList, ary, atob, attempt, average, averageBy, bifurcate, bifurcateBy, bind, bindAll, bindKey, binomialCoefficient, bottomVisible, btoa, byteSize, call, capitalize, capitalizeEveryWord, castArray, chainAsync, chunk, clampNumber, cloneRegExp, coalesce, coalesceFactory, collectInto, colorize, compact, compose, composeRight, converge, copyToClipboard, countBy, countOccurrences, counter, createElement, createEventHub, currentURL, curry, dayOfYear, debounce, decapitalize, deepClone, deepFlatten, deepFreeze, defaults, defer, degreesToRads, delay, detectDeviceType, difference, differenceBy, differenceWith, dig, digitize, distance, drop, dropRight, dropRightWhile, dropWhile, elementContains, elementIsVisibleInViewport, elo, equals, escapeHTML, escapeRegExp, everyNth, extendHex, factorial, fibonacci, filterNonUnique, filterNonUniqueBy, findKey, findLast, findLastIndex, findLastKey, flatten, flattenObject, flip, forEachRight, forOwn, forOwnRight, formatDuration, fromCamelCase, functionName, functions, gcd, geometricProgression, get, getColonTimeFromDate, getDaysDiffBetweenDates, getImages, getMeridiemSuffixOfInteger, getScrollPosition, getStyle, getType, getURLParameters, groupBy, hammingDistance, hasClass, hasFlags, hashBrowser, hashNode, head, hexToRGB, hide, httpGet, httpPost, httpsRedirect, hz, inRange, indentString, indexOfAll, initial, initialize2DArray, initializeArrayWithRange, initializeArrayWithRangeRight, initializeArrayWithValues, initializeNDArray, insertAfter, insertBefore, intersection, intersectionBy, intersectionWith, invertKeyValues, is, isAbsoluteURL, isAfterDate, isAnagram, isArrayLike, isBeforeDate, isBoolean, isBrowser, isBrowserTabFocused, isDivisible, isDuplexStream, isEmpty, isEven, isFunction, isLowerCase, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isPrime, isPrimitive, isPromiseLike, isReadableStream, isSameDate, isSorted, isStream, isString, isSymbol, isTravisCI, isUndefined, isUpperCase, isValidJSON, isWritableStream, join, last, lcm, longestItem, lowercaseKeys, luhnCheck, mapKeys, mapObject, mapString, mapValues, mask, matches, matchesWith, maxBy, maxDate, maxN, median, memoize, merge, minBy, minDate, minN, mostPerformant, negate, nest, nodeListToArray, none, nthArg, nthElement, objectFromPairs, objectToPairs, observeMutations, off, offset, omit, omitBy, on, onUserInputChange, once, orderBy, over, overArgs, pad, palindrome, parseCookie, partial, partialRight, partition, percentile, permutations, pick, pickBy, pipeAsyncFunctions, pipeFunctions, pluralize, powerset, prefix, prettyBytes, primes, promisify, pull, pullAtIndex, pullAtValue, pullBy, radsToDegrees, randomHexColorCode, randomIntArrayInRange, randomIntegerInRange, randomNumberInRange, readFileLines, rearg, recordAnimationFrames, redirect, reduceSuccessive, reduceWhich, reducedFilter, reject, remove, removeNonASCII, renameKeys, reverseString, round, runAsync, runPromisesInSeries, sample, sampleSize, scrollToTop, sdbm, serializeCookie, setStyle, shallowClone, shank, show, shuffle, similarity, size, sleep, smoothScroll, sortCharactersInString, sortedIndex, sortedIndexBy, sortedLastIndex, sortedLastIndexBy, splitLines, spreadOver, stableSort, standardDeviation, stringPermutations, stripHTMLTags, sum, sumBy, sumPower, symmetricDifference, symmetricDifferenceBy, symmetricDifferenceWith, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeTaken, times, toCamelCase, toCurrency, toDecimalMark, toHash, toKebabCase, toOrdinalSuffix, toSafeInteger, toSnakeCase, toTitleCase, toggleClass, tomorrow, transform, triggerEvent, truncateString, truthCheckCollection, unary, uncurry, unescapeHTML, unflattenObject, unfold, union, unionBy, unionWith, uniqueElements, uniqueElementsBy, uniqueElementsByRight, uniqueSymmetricDifference, untildify, unzip, unzipWith, validateNumber, when, without, words, xProd, yesNo, zip, zipObject, zipWith, JSONToDate, binarySearch, celsiusToFahrenheit, cleanObj, collatz, countVowels, factors, fahrenheitToCelsius, fibonacciCountUntilNum, fibonacciUntilNum, heronArea, howManyTimes, httpDelete, httpPut, isArmstrongNumber, isSimilar, kmphToMph, levenshteinDistance, mphToKmph, pipeLog, quickSort, removeVowels, solveRPN, speechSynthesis, squareSum};
|
|
|
|
|
|