Adapter
call
Given a key and a set of arguments, call them when given a context. Primarily useful in composition.
Use a closure to call a stored key with stored arguments.
const call = (key, ...args) => context => context[key](...args); + }
30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.
Adapter
ary
Creates a function that accepts up to
narguments, ignoring any additional arguments.Call the provided function,
fn, with up tonarguments, usingArray.slice(0,n)and the spread operator (...).const ary = (fn, n) => (...args) => fn(...args.slice(0, n)); +const firstTwoMax = ary(Math.max, 2); +[[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x)); // [6, 8, 10] +call
Given a key and a set of arguments, call them when given a context. Primarily useful in composition.
Use a closure to call a stored key with stored arguments.
const call = (key, ...args) => context => context[key](...args);Promise.resolve([1, 2, 3]) .then(call('map', x => 2 * x)) .then(console.log); //[ 2, 4, 6 ] @@ -72,6 +75,9 @@ Promise.reso mergePerson(b); // == b b = {}; Object.assign(b, a); // == b +over
Creates a function that invokes each provided function with the arguments it receives and returns the results.
Use
Array.map()andFunction.apply()to apply each function to the given arguments.const over = (...fns) => (...args) => fns.map(fn => fn.apply(null, args)); +const minMax = over(Math.min, Math.max); +minMax(1, 2, 3, 4, 5); // [1,5]pipeFunctions
Performs left-to-right function composition.
Use
Array.reduce()with the spread operator (...) to perform left-to-right function composition. The first (leftmost) function can accept one or more arguments; the remaining functions must be unary.const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));const add5 = x => x + 5; const multiply = (x, y) => x * y; @@ -86,6 +92,8 @@ Object.assigspreadOver
Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function.
Use closures and the spread operator (
...) to map the array of arguments to the inputs of the function.const spreadOver = fn => argsArr => fn(...argsArr);const arrayMax = spreadOver(Math.max); arrayMax([1, 2, 3]); // 3 +unary
Creates a function that accepts up to one argument, ignoring any additional arguments.
Call the provided function,
fn, with just the first argument given.const unary = fn => val => fn(val); +['6', '8', '10'].map(unary(parseInt)); // [6, 8, 10]Array
chunk
Chunks an array into smaller arrays of a specified size.
Use
Array.from()to create a new array, that fits the number of chunks that will be produced. UseArray.slice()to map each element of the new array to a chunk the length ofsize. If the original array can't be split evenly, the final chunk will contain the remaining elements.const chunk = (arr, size) => Array.from({ length: Math.ceil(arr.length / size) }, (v, i) => arr.slice(i * size, i * size + size) @@ -109,6 +117,12 @@ Object.assig return a.filter(x => !s.has(x)); };difference([1, 2, 3], [1, 2, 4]); // [3] +differenceBy
Returns the difference between two arrays, after applying the provided function to each array element of both.
Create a
Setby applyingfnto each element inb, then useArray.filter()in combination withfnonato only keep values not contained in the previously created set.const differenceBy = (a, b, fn) => { + const s = new Set(b.map(v => fn(v))); + return a.filter(x => !s.has(fn(x))); +}; +differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [1.2] +differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], v => v.x); // [ { x: 2 } ]differenceWith
Filters out all values from an array for which the comparator function does not return
true.Use
Array.filter()andArray.findIndex()to find the appropriate values.const differenceWith = (arr, val, comp) => arr.filter(a => val.findIndex(b => comp(a, b)) === -1);differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Math.round(b)); // [1, 1.2]dropElements
Removes elements in an array until the passed function returns
true. Returns the remaining elements in the array.Loop through the array, using
Array.slice()to drop the first element of the array until the returned value from the function istrue. Returns the remaining elements.const dropElements = (arr, func) => { @@ -124,8 +138,14 @@ Object.assigeveryNth([1, 2, 3, 4, 5, 6], 2); // [ 2, 4, 6 ]filterNonUnique
Filters out the non-unique values in an array.
Use
Array.filter()for an array containing only the unique values.const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i));filterNonUnique([1, 2, 2, 3, 4, 4, 5]); // [1,3,5] -findLast
Returns the last element for which the provided function returns a truthy value.
Use
Array.filter()to remove elements for whichfnreturns falsey values,Array.slice(-1)to get the last one.const findLast = (arr, fn) => arr.filter(fn).slice(-1); +findLast
Returns the last element for which the provided function returns a truthy value.
Use
Array.filter()to remove elements for whichfnreturns falsey values,Array.slice(-1)to get the last one.const findLast = (arr, fn) => arr.filter(fn).slice(-1)[0];findLast([1, 2, 3, 4], n => n % 2 === 1); // 3 +findLastIndex
Returns the index of the last element for which the provided function returns a truthy value.
Use
Array.map()to map each element to an array with its index and value. UseArray.filter()to remove elements for whichfnreturns falsey values,Array.slice(-1)to get the last one.const findLastIndex = (arr, fn) => + arr + .map((val, i) => [i, val]) + .filter(val => fn(val[1], val[0], arr)) + .slice(-1)[0][0]; +findLastIndex([1, 2, 3, 4], n => n % 2 === 1); // 2 (index of the value 3)flatten
Flattens an array up to the specified depth.
Use recursion, decrementing
depthby 1 for each level of depth. UseArray.reduce()andArray.concat()to merge elements or arrays. Base case, fordepthequal to1stops recursion. Omit the second argument,depthto flatten only to a depth of1(single flatten).const flatten = (arr, depth = 1) => depth != 1 ? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flatten(v, depth - 1) : v), []) @@ -178,6 +198,13 @@ Object.assig return a.filter(x => s.has(x)); };intersection([1, 2, 3], [4, 3, 2]); // [2,3] +intersectionBy
Returns a list of elements that exist in both arrays, after applying the provided function to each array element of both.
Create a
Setby applyingfnto all elements inb, then useArray.filter()onato only keep elements, which produce values contained inbwhenfnis applied to them.const intersectionBy = (a, b, fn) => { + const s = new Set(b.map(x => fn(x))); + return a.filter(x => s.has(fn(x))); +}; +intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [2.1] +intersectionWith
Returns a list of elements that exist in both arrays, using a provided comparator function.
Use
Array.filter()andArray.findIndex()in combination with the provided comparator to determine intersecting values.const intersectionWith = (a, b, comp) => a.filter(x => b.findIndex(y => comp(x, y)) !== -1); +intersectionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)); // [1.5, 3, 0]isSorted
Returns
1if the array is sorted in ascending order,-1if it is sorted in descending order or0if it is not sorted.Calculate the ordering
directionfor the first two elements. UseObject.entries()to loop over array objects and compare them in pairs. Return0if thedirectionchanges or thedirectionif the last element is reached.const isSorted = arr => { const direction = arr[0] > arr[1] ? -1 : 1; for (let [i, val] of arr.entries()) @@ -281,6 +308,17 @@ Object.assig ]; reducedFilter(data, ['id', 'name'], item => item.age > 24); // [{ id: 2, name: 'mike'}] +reduceSuccessive
Applies a function against an accumulator and each element in the array (from left to right), returning an array of successively reduced values.
Use
Array.reduce()to apply the given function to the given array, storing each new result.const reduceSuccessive = (arr, fn, acc) => + arr.reduce((res, val, i, arr) => (res.push(fn(res.slice(-1)[0], val, i, arr)), res), [acc]); +reduceSuccessive([1, 2, 3, 4, 5, 6], (acc, val) => acc + val, 0); // [0, 1, 3, 6, 10, 15, 21] +reduceWhich
Returns the minimum/maximum value of an array, after applying the provided function to set comparing rule.
Use
Array.reduce()in combination with thecomparatorfunction to get the appropriate element in the array. You can omit the second parameter,comparator, to use the default one that returns the minimum element in the array.const reduceWhich = (arr, comparator = (a, b) => a - b) => + arr.reduce((a, b) => (comparator(a, b) >= 0 ? b : a)); +reduceWhich([1, 3, 2]); // 1 +reduceWhich([1, 3, 2], (a, b) => b - a); // 3 +reduceWhich( + [{ name: 'Tom', age: 12 }, { name: 'Jack', age: 18 }, { name: 'Lucy', age: 9 }], + (a, b) => a.age - b.age +); // {name: "Lucy", age: 9}remove
Removes elements from an array for which the given function returns
false.Use
Array.filter()to find array elements that return truthy values andArray.reduce()to remove elements usingArray.splice(). Thefuncis invoked with three arguments (value, index, array).const remove = (arr, func) => Array.isArray(arr) ? arr.filter(func).reduce((acc, val) => { @@ -320,12 +358,36 @@ Object.assig };sortedIndex([5, 3, 2, 1], 4); // 1 sortedIndex([30, 50], 40); // 1 +sortedLastIndex
Returns the highest index at which value should be inserted into array in order to maintain its sort order.
Check if the array is sorted in descending order (loosely). Use
Array.map()to map each element to an array with its index and value. UseArray.filter()to find all possible positions where the element could be inserted,Array.slice(-1)to get the last one.const sortedLastIndex = (arr, n) => { + const isDescending = arr[0] > arr[arr.length - 1]; + const index = arr + .map((val, i) => [i, val]) + .filter(el => (isDescending ? n >= el[1] : n >= el[1])) + .slice(-1)[0][0]; + return index === -1 ? arr.length : index; +}; +sortedLastIndex([10, 20, 30, 30, 40], 30); // 3symmetricDifference
Returns the symmetric difference between two arrays.
Create a
Setfrom each array, then useArray.filter()on each of them to only keep values not contained in the other.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))]; };symmetricDifference([1, 2, 3], [1, 2, 4]); // [3,4] +symmetricDifferenceBy
Returns the symmetric difference between two arrays, after applying the provided function to each array element of both.
Create a
Setby applyingfnto each array's elements, then useArray.filter()on each of them to only keep values not contained in the other.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)))]; +}; +symmetricDifferenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [ 1.2, 3.4 ] +symmetricDifferenceWith
Returns the symmetric difference between two arrays, using a provided function as a comparator.
Use
Array.filter()andArray.findIndex()to find the appropriate values.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) +]; +symmetricDifferenceWith( + [1, 1.2, 1.5, 3, 0], + [1.9, 3, 0, 3.9], + (a, b) => Math.round(a) === Math.round(b) +); // [1, 1.2, 3.9]tail
Returns all elements in an array except for the first one.
Return
Array.slice(1)if the array'slengthis more than1, otherwise, return the whole array.const tail = arr => (arr.length > 1 ? arr.slice(1) : arr);tail([1, 2, 3]); // [2,3] tail([1]); // [1] @@ -337,10 +399,39 @@ Object.assig takeRight([1, 2, 3]); // [3]union
Returns every element that exists in any of the two arrays once.
Create a
Setwith all values ofaandband convert to an array.const union = (a, b) => Array.from(new Set([...a, ...b]));union([1, 2, 3], [4, 3, 2]); // [1,2,3,4] +unionBy
Returns every element that exists in any of the two arrays once, after applying the provided function to each array element of both.
Create a
Setby applying allfnto all values ofa. Create aSetfromaand all elements inbwhose value, after applyingfndoes not match a value in the previously created set. Return the last set converted to an array.const unionBy = (a, b, fn) => { + const s = new Set(a.map(v => fn(v))); + return Array.from(new Set([...a, ...b.filter(x => !s.has(fn(x)))])); +}; +unionBy([2.1], [1.2, 2.3], Math.floor); // [2.1, 1.2] +unionWith
Returns every element that exists in any of the two arrays once, using a provided comparator function.
Create a
Setwith all values ofaand values inbfor which the comparator finds no matches ina, usingArray.findIndex().const unionWith = (a, b, comp) => + Array.from(new Set([...a, ...b.filter(x => a.findIndex(y => comp(x, y)) === -1)])); +unionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)); // [1, 1.2, 1.5, 3, 0, 3.9]uniqueElements
Returns all unique values of an array.
Use ES6
Setand the...restoperator to discard all duplicated values.const uniqueElements = arr => [...new Set(arr)];uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1,2,3,4,5] +unzip
Creates an array of arrays, ungrouping the elements in an array produced by zip.
Use
Math.max.apply()to get the longest subarray in the array,Array.map()to make each element an array. UseArray.reduce()andArray.forEach()to map grouped values to individual arrays.const unzip = arr => + arr.reduce( + (acc, val) => (val.forEach((v, i) => acc[i].push(v)), acc), + Array.from({ + length: Math.max(...arr.map(x => x.length)) + }).map(x => []) + ); +unzip([['a', 1, true], ['b', 2, false]]); //[['a', 'b'], [1, 2], [true, false]] +unzip([['a', 1, true], ['b', 2]]); //[['a', 'b'], [1, 2], [true]] +unzipWithadvanced
Creates an array of elements, ungrouping the elements in an array produced by zip and applying the provided function.
Use
Math.max.apply()to get the longest subarray in the array,Array.map()to make each element an array. UseArray.reduce()andArray.forEach()to map grouped values to individual arrays. UseArray.map()and the spread operator (...) to applyfnto each individual group of elements.const unzipWith = (arr, fn) => + arr + .reduce( + (acc, val) => (val.forEach((v, i) => acc[i].push(v)), acc), + Array.from({ + length: Math.max(...arr.map(x => x.length)) + }).map(x => []) + ) + .map(val => fn(...val)); +unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0)); // [3, 30, 300]without
Filters out the elements of an array, that have one of the specified values.
Use
Array.filter()to create an array excluding(using!Array.includes()) all given values.(For a snippet that mutates the original array see
pull)const without = (arr, ...args) => arr.filter(v => !args.includes(v));without([2, 1, 2, 3], 1, 2); // [3] +xProd
Creates a new array out of the two supplied by creating each possible pair from the arrays.
Use
Array.reduce(),Array.map()andArray.concat()to produce every possible pair from the elements of the two arrays and save them in an array.const xProd = (a, b) => a.reduce((acc, x) => acc.concat(b.map(y => [x, y])), []); +xProd([1, 2], ['a', 'b']); // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]zip
Creates an array of elements, grouped based on the position in the original arrays.
Use
Math.max.apply()to get the longest array in the arguments. Creates an array with that length as return value and useArray.from()with a map-function to create an array of grouped elements. If lengths of the argument-arrays vary,undefinedis used where no value could be found.const zip = (...arrays) => { const maxLength = Math.max(...arrays.map(x => x.length)); return Array.from({ length: maxLength }).map((_, i) => { @@ -353,6 +444,23 @@ Object.assig props.reduce((obj, prop, index) => ((obj[prop] = values[index]), obj), {});zipObject(['a', 'b', 'c'], [1, 2]); // {a: 1, b: 2, c: undefined} zipObject(['a', 'b'], [1, 2, 3]); // {a: 1, b: 2} +zipWithadvanced
Creates an array of elements, grouped based on the position in the original arrays and using function as the last value to specify how grouped values should be combined.
Check if the last argument provided in a function. Use
Math.max()to get the longest array in the arguments. Creates an array with that length as return value and useArray.from()with a map-function to create an array of grouped elements. If lengths of the argument-arrays vary,undefinedis used where no value could be found. The function is invoked with the elements of each group(...group).const zipWith = (...arrays) => { + const length = arrays.length; + let fn = length > 1 ? arrays[length - 1] : undefined; + fn = typeof fn == 'function' ? (arrays.pop(), fn) : undefined; + const maxLength = Math.max(...arrays.map(x => x.length)); + const result = Array.from({ length: maxLength }).map((_, i) => { + return Array.from({ length: arrays.length }, (_, k) => arrays[k][i]); + }); + return fn ? result.map(arr => fn(...arr)) : result; +}; +zipWith([1, 2], [10, 20], [100, 200], (a, b, c) => a + b + c); // [111,222] +zipWith( + [1, 2, 3], + [10, 20], + [100, 200], + (a, b, c) => (a != null ? a : 'a') + (b != null ? b : 'b') + (c != null ? c : 'c') +); // [111, 222, '3bc']Browser
arrayToHtmlList
Converts the given array elements into
<li>tags and appends them to the list of the given id.Use
Array.map()anddocument.querySelector()to create a list of html tags.const arrayToHtmlList = (arr, listID) => arr.map(item => (document.querySelector('#' + listID).innerHTML += `<li>${item}</li>`));arrayToHtmlList(['item 1', 'item 2'], 'myListID'); @@ -588,9 +696,37 @@ document.body📋 Copy to clipboardgetDaysDiffBetweenDates
Returns the difference (in days) between two dates.
Calculate the difference (in days) between two
Dateobjects.const getDaysDiffBetweenDates = (dateInitial, dateFinal) => (dateFinal - dateInitial) / (1000 * 3600 * 24);getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22')); // 9 -tomorrow
Results in a string representation of tomorrow's date. Use
new Date()to get today's date, adding86400000of seconds to it(24 hours), usingDate.toISOString()to convert Date object to string.const tomorrow = () => new Date(new Date().getTime() + 86400000).toISOString().split('T')[0]; +tomorrow
Results in a string representation of tomorrow's date. Use
new Date()to get today's date, adding one day usingDate.getDate()andDate.setDate(), and converting the Date object to a string.const tomorrow = () => { + let t = new Date(); + t.setDate(t.getDate() + 1); + return `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, '0')}-${String( + t.getDate() + ).padStart(2, '0')}`; +};tomorrow(); // 2017-12-27 (if current date is 2017-12-26) -Function
chainAsync
Chains asynchronous functions.
Loop through an array of functions containing asynchronous events, calling
nextwhen each asynchronous event has completed.const chainAsync = fns => { +Function
bind
Creates a function that invokes
fnwith a given context, optionally adding any additional supplied parameters to the beginning of the arguments.Return a
functionthat usesFunction.apply()to apply the givencontexttofn. UseArray.concat()to prepend any additional supplied parameters to the arguments.const bind = (fn, context, ...args) => + function() { + return fn.apply(context, args.concat(...arguments)); + }; +function greet(greeting, punctuation) { + return greeting + ' ' + this.user + punctuation; +} +const freddy = { user: 'fred' }; +const freddyBound = bind(greet, freddy); +console.log(freddyBound('hi', '!')); // 'hi fred!' +bindKey
Creates a function that invokes the method at a given key of an object, optionally adding any additional supplied parameters to the beginning of the arguments.
Return a
functionthat usesFunction.apply()to bindcontext[fn]tocontext. UseArray.concat()to prepend any additional supplied parameters to the arguments.const bindKey = (context, fn, ...args) => + function() { + return context[fn].apply(context, args.concat(...arguments)); + }; +const freddy = { + user: 'fred', + greet: function(greeting, punctuation) { + return greeting + ' ' + this.user + punctuation; + } +}; +const freddyBound = bindKey(freddy, 'greet'); +console.log(freddyBound('hi', '!')); // 'hi fred!' +chainAsync
Chains asynchronous functions.
Loop through an array of functions containing asynchronous events, calling
nextwhen each asynchronous event has completed.const chainAsync = fns => { let curr = 0; const next = () => fns[curr++](next); next(); @@ -609,6 +745,11 @@ document.bodyconst multiply = (x, y) => x * y; const multiplyAndAdd5 = compose(add5, multiply); multiplyAndAdd5(5, 2); // 15 +composeRight
Performs left-to-right function composition.
Use
Array.reduce()to perform left-to-right function composition. The first (leftmost) function can accept one or more arguments; the remaining functions must be unary.const composeRight = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args))); +const add = (x, y) => x + y; +const square = x => x * x; +const addAndSquare = composeRight(add, square); +addAndSquare(1, 2); // 9curry
Curries a function.
Use recursion. If the number of provided arguments (
args) is sufficient, call the passed functionfn. Otherwise, return a curried functionfnthat expects the rest of the arguments. If you want to curry a function that accepts a variable number of arguments (a variadic function, e.g.Math.min()), you can optionally pass the number of arguments to the second parameterarity.const curry = (fn, arity = fn.length, ...args) => arity <= args.length ? fn(...args) : curry.bind(null, fn, arity, ...args);curry(Math.pow)(2)(10); // 1024 @@ -621,6 +762,14 @@ document.body.querySelector('#someElement').innerHTML = 'Hello'; longRunningFunction(); //Browser will not update the HTML until this has finished defer(longRunningFunction); // Browser will update the HTML then run the function +delay
Invokes the provided function after
waitmilliseconds.Use
setTimeout()to delay execution offn. Use the spread (...) operator to supply the function with an arbitrary number of arguments.const delay = (fn, wait, ...args) => setTimeout(fn, wait, ...args); +delay( + function(text) { + console.log(text); + }, + 1000, + 'later' +); // Logs 'later' after one second.functionName
Logs the name of a function.
Use
console.debug()and thenameproperty of the passed method to log the method's name to thedebugchannel of the console.const functionName = fn => (console.debug(fn.name), fn);functionName(Math.max); // max (logged in debug channel of console)memoize
Returns the memoized (cached) function.
Create an empty cache by instantiating a new
Mapobject. Return a function which takes a single argument to be supplied to the memoized function by first checking if the function's output for that specific input value is already cached, or store and return it if not. Thefunctionkeyword must be used in order to allow the memoized function to have itsthiscontext changed if necessary. Allow access to thecacheby setting it as a property on the returned function.const memoize = fn => { @@ -650,6 +799,18 @@ console.log< console.log(this, event); // document.body, MouseEvent }; document.body.addEventListener('click', once(startApp)); // only runs `startApp` once upon click +partial
Creates a function that invokes
fnwithpartialsprepended to the arguments it receives.Use the spread operator (
...) to prependpartialsto the list of arguments offn.const partial = (fn, ...partials) => (...args) => fn(...partials, ...args); +function greet(greeting, name) { + return greeting + ' ' + name + '!'; +} +const greetHello = partial(greet, 'Hello'); +greetHello('John'); // 'Hello John!' +partialRight
Creates a function that invokes
fnwithpartialsappended to the arguments it receives.Use the spread operator (
...) to appendpartialsto the list of arguments offn.const partialRight = (fn, ...partials) => (...args) => fn(...args, ...partials); +function greet(greeting, name) { + return greeting + ' ' + name + '!'; +} +const greetJohn = partialRight(greet, 'John'); +greetJohn('Hello'); // 'Hello John!'runPromisesInSeries
Runs an array of promises in series.
Use
Array.reduce()to create a promise chain, where each promise returns the next promise when resolved.const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.resolve());const delay = d => new Promise(r => setTimeout(r, d)); runPromisesInSeries([() => delay(1000), () => delay(2000)]); // Executes each promise sequentially, taking a total of 3 seconds to complete @@ -659,6 +820,21 @@ document.bodyawait sleep(1000); console.log('I woke up after 1 second.'); } +times
Iterates over a callback
ntimesUse
Function.call()to callfnntimes or until it returnsfalse. Omit the last argument,context, to use anundefinedobject (or the global object in non-strict mode).const times = (n, fn, context = undefined) => { + let i = 0; + while (fn.call(context, i) !== false && ++i < n) {} +}; +var output = ''; +times(5, i => (output += i)); +console.log(output); // 01234 +unfold
Builds an array, using an iterator function and an initial seed value.
Use a
whileloop andArray.push()to call the function repeatedly until it returnsfalse. The iterator function accepts one argument (seed) and must always return an array with two elements ([value,nextSeed]) orfalseto terminate.const unfold = (fn, seed) => { + let result = [], + val = [null, seed]; + while ((val = fn(val[1]))) result.push(val[0]); + return result; +}; +var f = n => (n > 50 ? false : [-n, n + 10]); +unfold(f, 10); // [-10, -20, -30, -40, -50]Math
average
Returns the average of an of two or more numbers.
Use
Array.reduce()to add each value to an accumulator, initialized with a value of0, divide by thelengthof the array.const average = (...nums) => [...nums].reduce((acc, val) => acc + val, 0) / nums.length;average(...[1, 2, 3]); // 2 average(1, 2, 3); // 2 @@ -778,8 +954,8 @@ own individual rating by supplying it as the third argument. };median([5, 6, 50, 1, -5]); // 5minBy
Returns the minimum value of an array, after mapping each element to a value using the provided function.
Use
Array.map()to map each element to the value returned byfn,Math.min()to get the maximum value.const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : val => val[fn])); -minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 8 -minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 8 +minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 2 +minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 2percentile
Uses the percentile formula to calculate how many numbers in the given array are less or equal to the given value.
Use
Array.reduce()to calculate how many numbers are below the value and how many are the same value and apply the percentile formula.const percentile = (arr, val) => 100 * arr.reduce((acc, v) => acc + (v < val ? 1 : 0) + (v === val ? 0.5 : 0), 0) / arr.length;percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6); // 55 @@ -913,7 +1089,16 @@ console.log< (c ^ (crypto.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16) );UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc' -Object
defaults
Assigns default values for all properties in an object that are
undefined.Use
Object.assign()to create a new empty object and copy the original one to maintain key order, useArray.reverse()and the spread operator...to combine the default values from left to right, finally useobjagain to overwrite properties that originally had a value.const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj); +Object
deepClone
Creates a deep clone of an object.
Use recursion. Use
Object.assign()and an empty object ({}) to create a shallow clone of the original. UseObject.keys()andArray.forEach()to determine which key-value pairs need to be deep cloned.const deepClone = obj => { + let clone = Object.assign({}, obj); + Object.keys(clone).forEach( + key => (clone[key] = typeof obj[key] === 'object' ? deepClone(obj[key]) : obj[key]) + ); + return clone; +}; +const a = { foo: 'bar', obj: { a: 1, b: 2 } }; +const b = deepClone(a); // a !== b, a.obj !== b.obj +defaults
Assigns default values for all properties in an object that are
undefined.Use
Object.assign()to create a new empty object and copy the original one to maintain key order, useArray.reverse()and the spread operator...to combine the default values from left to right, finally useobjagain to overwrite properties that originally had a value.const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj);defaults({ a: 1 }, { b: 2 }, { b: 6 }, { a: 3 }); // { a: 1, b: 2 }equalsadvanced
Performs a deep comparison between two values to determine if they are equivalent.
Check if the two values are identical, if they are both
Dateobjects with the same time, usingDate.getTime()or if they are both non-object values with an equivalent value (strict comparison). Check if only one value isnullorundefinedor if their prototypes differ. If none of the above conditions are met, useObject.keys()to check if both values have the same number of keys, then useArray.every()to check if every key in the first value exists in the second one and if they are equivalent by calling this method recursively.const equals = (a, b) => { if (a === b) return true; @@ -926,6 +1111,27 @@ console.log< return keys.every(k => equals(a[k], b[k])); };equals({ a: [2, { e: 3 }], b: [4], c: 'foo' }, { a: [2, { e: 3 }], b: [4], c: 'foo' }); // true +findKey
Returns the first key that satisfies the provided testing function. Otherwise
undefinedis returned.Use
Object.keys(obj)to get all the properties of the object,Array.find()to test the provided function for each key-value pair. The callback receives three arguments - the value, the key and the object.const findKey = (obj, fn) => Object.keys(obj).find(key => fn(obj[key], key, obj)); +findKey( + { + barney: { age: 36, active: true }, + fred: { age: 40, active: false }, + pebbles: { age: 1, active: true } + }, + o => o['active'] +); // 'barney' +findLastKey
Returns the last key that satisfies the provided testing function. Otherwise
undefinedis returned.Use
Object.keys(obj)to get all the properties of the object,Array.reverse()to reverse their order andArray.find()to test the provided function for each key-value pair. The callback receives three arguments - the value, the key and the object.const findLastKey = (obj, fn) => + Object.keys(obj) + .reverse() + .find(key => fn(obj[key], key, obj)); +findLastKey( + { + barney: { age: 36, active: true }, + fred: { age: 40, active: false }, + pebbles: { age: 1, active: true } + }, + o => o['active'] +); // 'pebbles'forOwn
Iterates over all own properties of an object, running a callback for each one.
Use
Object.keys(obj)to get all the properties of the object,Array.forEach()to run the provided function for each key-value pair. The callback receives three arguments - the value, the key and the object.const forOwn = (obj, fn) => Object.keys(obj).forEach(key => fn(obj[key], key, obj));forOwn({ foo: 'bar', a: 1 }, v => console.log(v)); // 'bar', 1forOwnRight
Iterates over all own properties of an object in reverse, running a callback for each one.
Use
Object.keys(obj)to get all the properties of the object,Array.reverse()to reverse their order andArray.forEach()to run the provided function for each key-value pair. The callback receives three arguments - the value, the key and the object.const forOwnRight = (obj, fn) => @@ -955,12 +1161,15 @@ Foo.prototypeShow examplesconst obj = { selector: { to: { val: 'val to select' } }, target: [1, 2, { a: 'test' }] }; get(obj, 'selector.to.val', 'target[0]', 'target[2].a'); // ['val to select', 1, 'test'] -invertKeyValues
Inverts the key-value pairs of an object, without mutating it.
Use
Object.keys()andArray.reduce()to invert the key-value pairs of an object.const invertKeyValues = obj => +invertKeyValues
Inverts the key-value pairs of an object, without mutating it. The corresponding inverted value of each inverted key is an array of keys responsible for generating the inverted value. If a function is supplied, it is applied to each inverted key.
Use
Object.keys()andArray.reduce()to invert the key-value pairs of an object and apply the function provided (if any). Omit the second argument,fn, to get the inverted keys without applying a function to them.const invertKeyValues = (obj, fn) => Object.keys(obj).reduce((acc, key) => { - acc[obj[key]] = key; + const val = fn ? fn(obj[key]) : obj[key]; + acc[val] = acc[val] || []; + acc[val].push(key); return acc; }, {}); -invertKeyValues({ name: 'John', age: 20 }); // { 20: 'age', John: 'name' } +invertKeyValues({ a: 1, b: 2, c: 1 }); // { 1: [ 'a', 'c' ], 2: [ 'b' ] } +invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value); // { group1: [ 'a', 'c' ], group2: [ 'b' ] }lowercaseKeys
Creates a new object from the specified object, where all the keys are in lowercase.
Use
Object.keys()andArray.reduce()to create a new object from the specified object. Convert each key in the original object to lowercase, usingString.toLowerCase().const lowercaseKeys = obj => Object.keys(obj).reduce((acc, key) => { acc[key.toLowerCase()] = obj[key]; @@ -984,6 +1193,23 @@ Foo.prototype: { user: 'pebbles', age: 1 } }; mapValues(users, u => u.age); // { fred: 40, pebbles: 1 } +matches
Compares two objects to determine if the first one contains equivalent property values to the second one.
Use
Object.keys(source)to get all the keys of the second object, thenArray.every(),Object.hasOwnProperty()and strict comparison to determine if all keys exist in the first object and have the same values.const matches = (obj, source) => + Object.keys(source).every(key => obj.hasOwnProperty(key) && obj[key] === source[key]); +matches({ age: 25, hair: 'long', beard: true }, { hair: 'long', beard: true }); // true +matches({ hair: 'long', beard: true }, { age: 25, hair: 'long', beard: true }); // false +matchesWith
Compares two objects to determine if the first one contains equivalent property values to the second one, based on a provided function.
Use
Object.keys(source)to get all the keys of the second object, thenArray.every(),Object.hasOwnProperty()and the provided function to determine if all keys exist in the first object and have equivalent values. If no function is provided, the values will be compared using the equality operator.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] + ); +const isGreeting = val => /^h(?:i|ello)$/.test(val); +matchesWith( + { greeting: 'hello' }, + { greeting: 'hi' }, + (oV, sV) => isGreeting(oV) && isGreeting(sV) +); // truemerge
Creates a new object from the combination of two or more objects.
Use
Array.reduce()combined withObject.keys(obj)to iterate over all objects and keys. UsehasOwnProperty()andArray.concat()to append values for keys existing in multiple objects.const merge = (...objs) => [...objs].reduce( (acc, obj) => @@ -1253,6 +1479,17 @@ Foo.prototype📋 Copy to clipboardisBoolean
Checks if the given argument is a native boolean element.
Use
typeofto check if a value is classified as a boolean primitive.const isBoolean = val => typeof val === 'boolean';isBoolean(null); // false isBoolean(false); // true +isEmpty
Returns true if the a value is an empty object, collection, map or set, has no enumerable properties or is any type that is not considered a collection.
Check if the provided value is
nullor if itslengthis equal to0.const isEmpty = val => val == null || !(Object.keys(val) || val).length; +isEmpty(new Map()); // true +isEmpty(new Set()); // true +isEmpty([]); // true +isEmpty({}); // true +isEmpty(''); // true +isEmpty([1, 2]); // false +isEmpty({ a: 1, b: 2 }); // false +isEmpty('text'); // false +isEmpty(123); // true - type is not considered a collection +isEmpty(true); // true - type is not considered a collectionisFunction
Checks if the given argument is a function.
Use
typeofto check if a value is classified as a function primitive.const isFunction = val => typeof val === 'function';isFunction('x'); // false isFunction(x => x); // true @@ -1271,6 +1508,11 @@ Foo.prototypeisObject({ a: 1 }); // true isObject({}); // true isObject(true); // false +isObjectLike
Checks if a value is object-like.
Check if the provided value is not
nulland itstypeofis equal to'object'.const isObjectLike = val => val !== null && typeof val === 'object'; +isObjectLike({}); // true +isObjectLike([1, 2, 3]); // true +isObjectLike(x => x); // false +isObjectLike(null); // falseisPlainObject
Checks if the provided value is an bbject created by the Object constructor.
Check if the provided value is truthy, use
typeofto check if it is an object andObject.constructorto make sure the constructor is equal toObject.const isPlainObject = val => !!val && typeof val === 'object' && val.constructor === Object;isPlainObject({ a: 1 }); // true isPlainObject(new Map()); // false @@ -1309,7 +1551,10 @@ Foo.prototypeShow examplesisValidJSON('{"name":"Adam","age":20}'); // true isValidJSON('{"name":"Adam",age:"20"}'); // false isValidJSON(null); // true -Utility
cloneRegExp
Clones a regular expression.
Use
new RegExp(),RegExp.sourceandRegExp.flagsto clone the given regular expression.const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags); +Utility
castArray
Casts the provided value as an array if it's not one.
Use
Array.isArray()to determine ifvalis an array and return it as-is or encapsulated in an array accordingly.const castArray = val => (Array.isArray(val) ? val : [val]); +castArray('foo'); // ['foo'] +castArray([1]); // [1] +cloneRegExp
Clones a regular expression.
Use
new RegExp(),RegExp.sourceandRegExp.flagsto clone the given regular expression.const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);const regExp = /lorem ipsum/gi; const regExp2 = cloneRegExp(regExp); // /lorem ipsum/gicoalesce
Returns the first non-null/undefined argument.
Use
Array.find()to return the first nonnull/undefinedargument.const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_)); @@ -1407,6 +1652,12 @@ Logs: { "id": 101 } */ +nthArg
Creates a function that gets the argument at index
n. Ifnis negative, the nth argument from the end is returned.Use
Array.slice()to get the desired argument at indexn.const nthArg = n => (...args) => args.slice(n)[0]; +const third = nthArg(2); +third(1, 2, 3); // 3 +third(1, 2); // undefined +const last = nthArg(-1); +last(1, 2, 3, 4, 5); // 5parseCookie
Parse an HTTP Cookie header string and return an object of all cookie name-value pairs.
Use
String.split(';')to separate key-value pairs from each other. UseArray.map()andString.split('=')to separate keys from values in each pair. UseArray.reduce()anddecodeURIComponent()to create an object with all key-value pairs.const parseCookie = str => str .split(';') diff --git a/scripts/tag.js b/scripts/tag.js index 733e45f18..e4bbc80e9 100644 --- a/scripts/tag.js +++ b/scripts/tag.js @@ -57,7 +57,6 @@ try { }) ); tagDbStats = Object.entries(tagDbData) - .sort((a, b) => a[1][0].localeCompare(b[1][0])) .reduce((acc, val) => { val[1].forEach(v => acc.hasOwnProperty(v) ? acc[v]++ : (acc[v] = 1)); return acc; @@ -89,7 +88,7 @@ try { } // Log statistics for the tag_database file console.log(`\n${chalk.bgWhite(chalk.black('=== TAG STATS ==='))}`); -for (let tagData of Object.entries(tagDbStats).filter(v => v[0] !== 'undefined')) +for (let tagData of Object.entries(tagDbStats).filter(v => v[0] !== 'undefined').sort((a,b) => a[0].localeCompare(b[0]))) console.log(`${chalk.green(tagData[0])}: ${tagData[1]} snippets`); console.log( `${chalk.blue("New untagged snippets (will be tagged as 'uncategorized'):")} ${missingTags}\n` diff --git a/scripts/tdd.js b/scripts/tdd.js index f93df6b66..71e55df85 100644 --- a/scripts/tdd.js +++ b/scripts/tdd.js @@ -23,7 +23,7 @@ const snippetFiles = []; const snippetFilesActive = fs.readdirSync(SNIPPETS_ACTIVE, 'utf8').map(fileName => fileName.slice(0, -3)); const snippetFilesArchive = fs.readdirSync(SNIPPETS_ARCHIVE, 'utf8') - .filter(fileName => !fileName.includes('README')) // -> Filters out main README.md file in Archieve which isn't a snippet + .filter(fileName => !fileName.includes('README')) // -> Filters out main README.md file in Archieve which isn't a snippet .map(fileName => fileName.slice(0, -3)); snippetFiles.push(...snippetFilesActive); @@ -46,35 +46,35 @@ snippetFiles const fileCode = fileData.slice(fileData.search(/```\s*js/i), fileData.lastIndexOf('```') + 3); // Split code based on code markers const blockMarkers = fileCode - .split('\n') - .map((line, lineIndex) => (line.slice(0, 3) === '```' ? lineIndex : '//CLEAR//')) - .filter(x => !(x === '//CLEAR//')); + .split('\n') + .map((line, lineIndex) => (line.slice(0, 3) === '```' ? lineIndex : '//CLEAR//')) + .filter(x => !(x === '//CLEAR//')); // Grab snippet function based on code markers const fileFunction = fileCode - .split('\n') - .map(line => line.trim()) - .filter((_, i) => blockMarkers[0] < i && i < blockMarkers[1]); + .split('\n') + .map(line => line.trim()) + .filter((_, i) => blockMarkers[0] < i && i < blockMarkers[1]); // Grab snippet example based on code markers const fileExample = fileCode - .split('\n') - .map(line => line.trim()) - .filter((_, i) => blockMarkers[2] < i && i < blockMarkers[3]); + .split('\n') + .map(line => line.trim()) + .filter((_, i) => blockMarkers[2] < i && i < blockMarkers[3]); // Export template for snippetName.js - const exportFile = `${fileFunction.join('\n')}\n module.exports = ${fileName}`; + const exportFile = `${fileFunction.join('\n')}\nmodule.exports = ${fileName}`.trim(); // Export template for snippetName.test.js which generates a example test & other information const exportTest = [ `const test = require('tape');`, `const ${fileName} = require('./${fileName}.js');`, `\ntest('Testing ${fileName}', (t) => {`, - `\t//For more information on all the methods supported by tape\n\t//Please go to https://github.com/substack/tape`, - `\tt.true(typeof ${fileName} === 'function', '${fileName} is a Function');`, - `\t//t.deepEqual(${fileName}(args..), 'Expected');`, - `\t//t.equal(${fileName}(args..), 'Expected');`, - `\t//t.false(${fileName}(args..), 'Expected');`, - `\t//t.throws(${fileName}(args..), 'Expected');`, - `\tt.end();`, + ` //For more information on all the methods supported by tape\n //Please go to https://github.com/substack/tape`, + ` t.true(typeof ${fileName} === 'function', '${fileName} is a Function');`, + ` //t.deepEqual(${fileName}(args..), 'Expected');`, + ` //t.equal(${fileName}(args..), 'Expected');`, + ` //t.false(${fileName}(args..), 'Expected');`, + ` //t.throws(${fileName}(args..), 'Expected');`, + ` t.end();`, `});` ].join('\n'); diff --git a/snippets/ary.md b/snippets/ary.md new file mode 100644 index 000000000..5251d72cd --- /dev/null +++ b/snippets/ary.md @@ -0,0 +1,14 @@ +### ary + +Creates a function that accepts up to `n` arguments, ignoring any additional arguments. + +Call the provided function, `fn`, with up to `n` arguments, using `Array.slice(0,n)` and the spread operator (`...`). + +```js +const ary = (fn, n) => (...args) => fn(...args.slice(0, n)); +``` + +```js +const firstTwoMax = ary(Math.max, 2); +[[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x)); // [6, 8, 10] +``` diff --git a/snippets/bind.md b/snippets/bind.md new file mode 100644 index 000000000..c0a9402e2 --- /dev/null +++ b/snippets/bind.md @@ -0,0 +1,22 @@ +### bind + +Creates a function that invokes `fn` with a given context, optionally adding any additional supplied parameters to the beginning of the arguments. + +Return a `function` that uses `Function.apply()` to apply the given `context` to `fn`. +Use `Array.concat()` to prepend any additional supplied parameters to the arguments. + +```js +const bind = (fn, context, ...args) => + function() { + return fn.apply(context, args.concat(...arguments)); + }; +``` + +```js +function greet(greeting, punctuation) { + return greeting + ' ' + this.user + punctuation; +} +const freddy = { user: 'fred' }; +const freddyBound = bind(greet, freddy); +console.log(freddyBound('hi', '!')); // 'hi fred!' +``` diff --git a/snippets/bindKey.md b/snippets/bindKey.md new file mode 100644 index 000000000..147ad2ff7 --- /dev/null +++ b/snippets/bindKey.md @@ -0,0 +1,24 @@ +### bindKey + +Creates a function that invokes the method at a given key of an object, optionally adding any additional supplied parameters to the beginning of the arguments. + +Return a `function` that uses `Function.apply()` to bind `context[fn]` to `context`. +Use `Array.concat()` to prepend any additional supplied parameters to the arguments. + +```js +const bindKey = (context, fn, ...args) => + function() { + return context[fn].apply(context, args.concat(...arguments)); + }; +``` + +```js +const freddy = { + user: 'fred', + greet: function(greeting, punctuation) { + return greeting + ' ' + this.user + punctuation; + } +}; +const freddyBound = bindKey(freddy, 'greet'); +console.log(freddyBound('hi', '!')); // 'hi fred!' +``` diff --git a/snippets/castArray.md b/snippets/castArray.md new file mode 100644 index 000000000..67f5206ce --- /dev/null +++ b/snippets/castArray.md @@ -0,0 +1,14 @@ +### castArray + +Casts the provided value as an array if it's not one. + +Use `Array.isArray()` to determine if `val` is an array and return it as-is or encapsulated in an array accordingly. + +```js +const castArray = val => (Array.isArray(val) ? val : [val]); +``` + +```js +castArray('foo'); // ['foo'] +castArray([1]); // [1] +``` diff --git a/snippets/composeRight.md b/snippets/composeRight.md new file mode 100644 index 000000000..88deb7355 --- /dev/null +++ b/snippets/composeRight.md @@ -0,0 +1,17 @@ +### composeRight + +Performs left-to-right function composition. + +Use `Array.reduce()` to perform left-to-right function composition. +The first (leftmost) function can accept one or more arguments; the remaining functions must be unary. + +```js +const composeRight = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args))); +``` + +```js +const add = (x, y) => x + y; +const square = x => x * x; +const addAndSquare = composeRight(add, square); +addAndSquare(1, 2); // 9 +``` diff --git a/snippets/deepClone.md b/snippets/deepClone.md new file mode 100644 index 000000000..fe2af84eb --- /dev/null +++ b/snippets/deepClone.md @@ -0,0 +1,22 @@ +### deepClone + +Creates a deep clone of an object. + +Use recursion. +Use `Object.assign()` and an empty object (`{}`) to create a shallow clone of the original. +Use `Object.keys()` and `Array.forEach()` to determine which key-value pairs need to be deep cloned. + +```js +const deepClone = obj => { + let clone = Object.assign({}, obj); + Object.keys(clone).forEach( + key => (clone[key] = typeof obj[key] === 'object' ? deepClone(obj[key]) : obj[key]) + ); + return clone; +}; +``` + +```js +const a = { foo: 'bar', obj: { a: 1, b: 2 } }; +const b = deepClone(a); // a !== b, a.obj !== b.obj +``` diff --git a/snippets/delay.md b/snippets/delay.md new file mode 100644 index 000000000..da524837f --- /dev/null +++ b/snippets/delay.md @@ -0,0 +1,20 @@ +### delay + +Invokes the provided function after `wait` milliseconds. + +Use `setTimeout()` to delay execution of `fn`. +Use the spread (`...`) operator to supply the function with an arbitrary number of arguments. + +```js +const delay = (fn, wait, ...args) => setTimeout(fn, wait, ...args); +``` + +```js +delay( + function(text) { + console.log(text); + }, + 1000, + 'later' +); // Logs 'later' after one second. +``` diff --git a/snippets/differenceBy.md b/snippets/differenceBy.md new file mode 100644 index 000000000..626ba7cdc --- /dev/null +++ b/snippets/differenceBy.md @@ -0,0 +1,17 @@ +### differenceBy + +Returns the difference between two arrays, after applying the provided function to each array element of both. + +Create a `Set` by applying `fn` to each element in `b`, then use `Array.filter()` in combination with `fn` on `a` to only keep values not contained in the previously created set. + +```js +const differenceBy = (a, b, fn) => { + const s = new Set(b.map(v => fn(v))); + return a.filter(x => !s.has(fn(x))); +}; +``` + +```js +differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [1.2] +differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], v => v.x); // [ { x: 2 } ] +``` diff --git a/snippets/findKey.md b/snippets/findKey.md new file mode 100644 index 000000000..81e41d226 --- /dev/null +++ b/snippets/findKey.md @@ -0,0 +1,20 @@ +### findKey + +Returns the first key that satisfies the provided testing function. Otherwise `undefined` is returned. + +Use `Object.keys(obj)` to get all the properties of the object, `Array.find()` to test the provided function for each key-value pair. The callback receives three arguments - the value, the key and the object. + +```js +const findKey = (obj, fn) => Object.keys(obj).find(key => fn(obj[key], key, obj)); +``` + +```js +findKey( + { + barney: { age: 36, active: true }, + fred: { age: 40, active: false }, + pebbles: { age: 1, active: true } + }, + o => o['active'] +); // 'barney' +``` diff --git a/snippets/findLast.md b/snippets/findLast.md index 901920049..00263354a 100644 --- a/snippets/findLast.md +++ b/snippets/findLast.md @@ -5,7 +5,7 @@ Returns the last element for which the provided function returns a truthy value. Use `Array.filter()` to remove elements for which `fn` returns falsey values, `Array.slice(-1)` to get the last one. ```js -const findLast = (arr, fn) => arr.filter(fn).slice(-1); +const findLast = (arr, fn) => arr.filter(fn).slice(-1)[0]; ``` ```js diff --git a/snippets/findLastIndex.md b/snippets/findLastIndex.md new file mode 100644 index 000000000..70dccd442 --- /dev/null +++ b/snippets/findLastIndex.md @@ -0,0 +1,18 @@ +### findLastIndex + +Returns the index of the last element for which the provided function returns a truthy value. + +Use `Array.map()` to map each element to an array with its index and value. +Use `Array.filter()` to remove elements for which `fn` returns falsey values, `Array.slice(-1)` to get the last one. + +```js +const findLastIndex = (arr, fn) => + arr + .map((val, i) => [i, val]) + .filter(val => fn(val[1], val[0], arr)) + .slice(-1)[0][0]; +``` + +```js +findLastIndex([1, 2, 3, 4], n => n % 2 === 1); // 2 (index of the value 3) +``` diff --git a/snippets/findLastKey.md b/snippets/findLastKey.md new file mode 100644 index 000000000..1333a98d3 --- /dev/null +++ b/snippets/findLastKey.md @@ -0,0 +1,23 @@ +### findLastKey + +Returns the last key that satisfies the provided testing function. Otherwise `undefined` is returned. + +Use `Object.keys(obj)` to get all the properties of the object, `Array.reverse()` to reverse their order and `Array.find()` to test the provided function for each key-value pair. The callback receives three arguments - the value, the key and the object. + +```js +const findLastKey = (obj, fn) => + Object.keys(obj) + .reverse() + .find(key => fn(obj[key], key, obj)); +``` + +```js +findLastKey( + { + barney: { age: 36, active: true }, + fred: { age: 40, active: false }, + pebbles: { age: 1, active: true } + }, + o => o['active'] +); // 'pebbles' +``` diff --git a/snippets/intersectionBy.md b/snippets/intersectionBy.md new file mode 100644 index 000000000..3f28a78be --- /dev/null +++ b/snippets/intersectionBy.md @@ -0,0 +1,16 @@ +### intersectionBy + +Returns a list of elements that exist in both arrays, after applying the provided function to each array element of both. + +Create a `Set` by applying `fn` to all elements in `b`, then use `Array.filter()` on `a` to only keep elements, which produce values contained in `b` when `fn` is applied to them. + +```js +const intersectionBy = (a, b, fn) => { + const s = new Set(b.map(x => fn(x))); + return a.filter(x => s.has(fn(x))); +}; +``` + +```js +intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [2.1] +``` diff --git a/snippets/intersectionWith.md b/snippets/intersectionWith.md new file mode 100644 index 000000000..4aa7e0874 --- /dev/null +++ b/snippets/intersectionWith.md @@ -0,0 +1,13 @@ +### intersectionWith + +Returns a list of elements that exist in both arrays, using a provided comparator function. + +Use `Array.filter()` and `Array.findIndex()` in combination with the provided comparator to determine intersecting values. + +```js +const intersectionWith = (a, b, comp) => a.filter(x => b.findIndex(y => comp(x, y)) !== -1); +``` + +```js +intersectionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)); // [1.5, 3, 0] +``` diff --git a/snippets/invertKeyValues.md b/snippets/invertKeyValues.md index 2d4302145..e50ea0912 100644 --- a/snippets/invertKeyValues.md +++ b/snippets/invertKeyValues.md @@ -1,17 +1,21 @@ ### invertKeyValues -Inverts the key-value pairs of an object, without mutating it. +Inverts the key-value pairs of an object, without mutating it. The corresponding inverted value of each inverted key is an array of keys responsible for generating the inverted value. If a function is supplied, it is applied to each inverted key. -Use `Object.keys()` and `Array.reduce()` to invert the key-value pairs of an object. +Use `Object.keys()` and `Array.reduce()` to invert the key-value pairs of an object and apply the function provided (if any). +Omit the second argument, `fn`, to get the inverted keys without applying a function to them. ```js -const invertKeyValues = obj => +const invertKeyValues = (obj, fn) => Object.keys(obj).reduce((acc, key) => { - acc[obj[key]] = key; + const val = fn ? fn(obj[key]) : obj[key]; + acc[val] = acc[val] || []; + acc[val].push(key); return acc; }, {}); ``` ```js -invertKeyValues({ name: 'John', age: 20 }); // { 20: 'age', John: 'name' } +invertKeyValues({ a: 1, b: 2, c: 1 }); // { 1: [ 'a', 'c' ], 2: [ 'b' ] } +invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value); // { group1: [ 'a', 'c' ], group2: [ 'b' ] } ``` diff --git a/snippets/isEmpty.md b/snippets/isEmpty.md new file mode 100644 index 000000000..f620f3727 --- /dev/null +++ b/snippets/isEmpty.md @@ -0,0 +1,22 @@ +### isEmpty + +Returns true if the a value is an empty object, collection, map or set, has no enumerable properties or is any type that is not considered a collection. + +Check if the provided value is `null` or if its `length` is equal to `0`. + +```js +const isEmpty = val => val == null || !(Object.keys(val) || val).length; +``` + +```js +isEmpty(new Map()); // true +isEmpty(new Set()); // true +isEmpty([]); // true +isEmpty({}); // true +isEmpty(''); // true +isEmpty([1, 2]); // false +isEmpty({ a: 1, b: 2 }); // false +isEmpty('text'); // false +isEmpty(123); // true - type is not considered a collection +isEmpty(true); // true - type is not considered a collection +``` diff --git a/snippets/isObjectLike.md b/snippets/isObjectLike.md new file mode 100644 index 000000000..969fdecd4 --- /dev/null +++ b/snippets/isObjectLike.md @@ -0,0 +1,16 @@ +### isObjectLike + +Checks if a value is object-like. + +Check if the provided value is not `null` and its `typeof` is equal to `'object'`. + +```js +const isObjectLike = val => val !== null && typeof val === 'object'; +``` + +```js +isObjectLike({}); // true +isObjectLike([1, 2, 3]); // true +isObjectLike(x => x); // false +isObjectLike(null); // false +``` diff --git a/snippets/matches.md b/snippets/matches.md new file mode 100644 index 000000000..47610d3d8 --- /dev/null +++ b/snippets/matches.md @@ -0,0 +1,15 @@ +### matches + +Compares two objects to determine if the first one contains equivalent property values to the second one. + +Use `Object.keys(source)` to get all the keys of the second object, then `Array.every()`, `Object.hasOwnProperty()` and strict comparison to determine if all keys exist in the first object and have the same values. + +```js +const matches = (obj, source) => + Object.keys(source).every(key => obj.hasOwnProperty(key) && obj[key] === source[key]); +``` + +```js +matches({ age: 25, hair: 'long', beard: true }, { hair: 'long', beard: true }); // true +matches({ hair: 'long', beard: true }, { age: 25, hair: 'long', beard: true }); // false +``` diff --git a/snippets/matchesWith.md b/snippets/matchesWith.md new file mode 100644 index 000000000..a04814191 --- /dev/null +++ b/snippets/matchesWith.md @@ -0,0 +1,25 @@ +### matchesWith + +Compares two objects to determine if the first one contains equivalent property values to the second one, based on a provided function. + +Use `Object.keys(source)` to get all the keys of the second object, then `Array.every()`, `Object.hasOwnProperty()` and the provided function to determine if all keys exist in the first object and have equivalent values. +If no function is provided, the values will be compared using the equality operator. + +```js +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] + ); +``` + +```js +const isGreeting = val => /^h(?:i|ello)$/.test(val); +matchesWith( + { greeting: 'hello' }, + { greeting: 'hi' }, + (oV, sV) => isGreeting(oV) && isGreeting(sV) +); // true +``` diff --git a/snippets/minBy.md b/snippets/minBy.md index 594d83f5e..e9d8a53e2 100644 --- a/snippets/minBy.md +++ b/snippets/minBy.md @@ -9,6 +9,6 @@ const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : v ``` ```js -minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 8 -minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 8 +minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 2 +minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 2 ``` diff --git a/snippets/nthArg.md b/snippets/nthArg.md new file mode 100644 index 000000000..159975b89 --- /dev/null +++ b/snippets/nthArg.md @@ -0,0 +1,17 @@ +### nthArg + +Creates a function that gets the argument at index `n`. If `n` is negative, the nth argument from the end is returned. + +Use `Array.slice()` to get the desired argument at index `n`. + +```js +const nthArg = n => (...args) => args.slice(n)[0]; +``` + +```js +const third = nthArg(2); +third(1, 2, 3); // 3 +third(1, 2); // undefined +const last = nthArg(-1); +last(1, 2, 3, 4, 5); // 5 +``` diff --git a/snippets/omitBy.md b/snippets/omitBy.md index 5a4928ebc..81ac1fc45 100644 --- a/snippets/omitBy.md +++ b/snippets/omitBy.md @@ -14,3 +14,4 @@ const omitBy = (obj, fn) => ```js omitBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number'); // { b: '2' } +``` diff --git a/snippets/over.md b/snippets/over.md new file mode 100644 index 000000000..31ab12963 --- /dev/null +++ b/snippets/over.md @@ -0,0 +1,14 @@ +### over + +Creates a function that invokes each provided function with the arguments it receives and returns the results. + +Use `Array.map()` and `Function.apply()` to apply each function to the given arguments. + +```js +const over = (...fns) => (...args) => fns.map(fn => fn.apply(null, args)); +``` + +```js +const minMax = over(Math.min, Math.max); +minMax(1, 2, 3, 4, 5); // [1,5] +``` diff --git a/snippets/partial.md b/snippets/partial.md new file mode 100644 index 000000000..17a53b49e --- /dev/null +++ b/snippets/partial.md @@ -0,0 +1,17 @@ +### partial + +Creates a function that invokes `fn` with `partials` prepended to the arguments it receives. + +Use the spread operator (`...`) to prepend `partials` to the list of arguments of `fn`. + +```js +const partial = (fn, ...partials) => (...args) => fn(...partials, ...args); +``` + +```js +function greet(greeting, name) { + return greeting + ' ' + name + '!'; +} +const greetHello = partial(greet, 'Hello'); +greetHello('John'); // 'Hello John!' +``` diff --git a/snippets/partialRight.md b/snippets/partialRight.md new file mode 100644 index 000000000..d64f7f1d6 --- /dev/null +++ b/snippets/partialRight.md @@ -0,0 +1,17 @@ +### partialRight + +Creates a function that invokes `fn` with `partials` appended to the arguments it receives. + +Use the spread operator (`...`) to append `partials` to the list of arguments of `fn`. + +```js +const partialRight = (fn, ...partials) => (...args) => fn(...args, ...partials); +``` + +```js +function greet(greeting, name) { + return greeting + ' ' + name + '!'; +} +const greetJohn = partialRight(greet, 'John'); +greetJohn('Hello'); // 'Hello John!' +``` diff --git a/snippets/reduceSuccessive.md b/snippets/reduceSuccessive.md new file mode 100644 index 000000000..dc4b154ed --- /dev/null +++ b/snippets/reduceSuccessive.md @@ -0,0 +1,14 @@ +### reduceSuccessive + +Applies a function against an accumulator and each element in the array (from left to right), returning an array of successively reduced values. + +Use `Array.reduce()` to apply the given function to the given array, storing each new result. + +```js +const reduceSuccessive = (arr, fn, acc) => + arr.reduce((res, val, i, arr) => (res.push(fn(res.slice(-1)[0], val, i, arr)), res), [acc]); +``` + +```js +reduceSuccessive([1, 2, 3, 4, 5, 6], (acc, val) => acc + val, 0); // [0, 1, 3, 6, 10, 15, 21] +``` diff --git a/snippets/reduceWhich.md b/snippets/reduceWhich.md new file mode 100644 index 000000000..49a188ce6 --- /dev/null +++ b/snippets/reduceWhich.md @@ -0,0 +1,20 @@ +### reduceWhich + +Returns the minimum/maximum value of an array, after applying the provided function to set comparing rule. + +Use `Array.reduce()` in combination with the `comparator` function to get the appropriate element in the array. +You can omit the second parameter, `comparator`, to use the default one that returns the minimum element in the array. + +```js +const reduceWhich = (arr, comparator = (a, b) => a - b) => + arr.reduce((a, b) => (comparator(a, b) >= 0 ? b : a)); +``` + +```js +reduceWhich([1, 3, 2]); // 1 +reduceWhich([1, 3, 2], (a, b) => b - a); // 3 +reduceWhich( + [{ name: 'Tom', age: 12 }, { name: 'Jack', age: 18 }, { name: 'Lucy', age: 9 }], + (a, b) => a.age - b.age +); // {name: "Lucy", age: 9} +``` diff --git a/snippets/sortedLastIndex.md b/snippets/sortedLastIndex.md new file mode 100644 index 000000000..ca6e327ba --- /dev/null +++ b/snippets/sortedLastIndex.md @@ -0,0 +1,22 @@ +### sortedLastIndex + +Returns the highest index at which value should be inserted into array in order to maintain its sort order. + +Check if the array is sorted in descending order (loosely). +Use `Array.map()` to map each element to an array with its index and value. +Use `Array.filter()` to find all possible positions where the element could be inserted, `Array.slice(-1)` to get the last one. + +```js +const sortedLastIndex = (arr, n) => { + const isDescending = arr[0] > arr[arr.length - 1]; + const index = arr + .map((val, i) => [i, val]) + .filter(el => (isDescending ? n >= el[1] : n >= el[1])) + .slice(-1)[0][0]; + return index === -1 ? arr.length : index; +}; +``` + +```js +sortedLastIndex([10, 20, 30, 30, 40], 30); // 3 +``` diff --git a/snippets/symmetricDifferenceBy.md b/snippets/symmetricDifferenceBy.md new file mode 100644 index 000000000..250eeaa03 --- /dev/null +++ b/snippets/symmetricDifferenceBy.md @@ -0,0 +1,17 @@ +### symmetricDifferenceBy + +Returns the symmetric difference between two arrays, after applying the provided function to each array element of both. + +Create a `Set` by applying `fn` to each array's elements, then use `Array.filter()` on each of them to only keep values not contained in the other. + +```js +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)))]; +}; +``` + +```js +symmetricDifferenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [ 1.2, 3.4 ] +``` diff --git a/snippets/symmetricDifferenceWith.md b/snippets/symmetricDifferenceWith.md new file mode 100644 index 000000000..5eab574fa --- /dev/null +++ b/snippets/symmetricDifferenceWith.md @@ -0,0 +1,20 @@ +### symmetricDifferenceWith + +Returns the symmetric difference between two arrays, using a provided function as a comparator. + +Use `Array.filter()` and `Array.findIndex()` to find the appropriate values. + +```js +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) +]; +``` + +```js +symmetricDifferenceWith( + [1, 1.2, 1.5, 3, 0], + [1.9, 3, 0, 3.9], + (a, b) => Math.round(a) === Math.round(b) +); // [1, 1.2, 3.9] +``` diff --git a/snippets/times.md b/snippets/times.md new file mode 100644 index 000000000..2563ff5bc --- /dev/null +++ b/snippets/times.md @@ -0,0 +1,19 @@ +### times + +Iterates over a callback `n` times + +Use `Function.call()` to call `fn` `n` times or until it returns `false`. +Omit the last argument, `context`, to use an `undefined` object (or the global object in non-strict mode). + +```js +const times = (n, fn, context = undefined) => { + let i = 0; + while (fn.call(context, i) !== false && ++i < n) {} +}; +``` + +```js +var output = ''; +times(5, i => (output += i)); +console.log(output); // 01234 +``` diff --git a/snippets/tomorrow.md b/snippets/tomorrow.md index 3bd5a6412..fd7c4dfa1 100644 --- a/snippets/tomorrow.md +++ b/snippets/tomorrow.md @@ -1,10 +1,16 @@ ### tomorrow Results in a string representation of tomorrow's date. -Use `new Date()` to get today's date, adding `86400000` of seconds to it(24 hours), using `Date.toISOString()` to convert Date object to string. +Use `new Date()` to get today's date, adding one day using `Date.getDate()` and `Date.setDate()`, and converting the Date object to a string. ```js -const tomorrow = () => new Date(new Date().getTime() + 86400000).toISOString().split('T')[0]; +const tomorrow = () => { + let t = new Date(); + t.setDate(t.getDate() + 1); + return `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, '0')}-${String( + t.getDate() + ).padStart(2, '0')}`; +}; ``` ```js diff --git a/snippets/unary.md b/snippets/unary.md new file mode 100644 index 000000000..51fa353cc --- /dev/null +++ b/snippets/unary.md @@ -0,0 +1,13 @@ +### unary + +Creates a function that accepts up to one argument, ignoring any additional arguments. + +Call the provided function, `fn`, with just the first argument given. + +```js +const unary = fn => val => fn(val); +``` + +```js +['6', '8', '10'].map(unary(parseInt)); // [6, 8, 10] +``` diff --git a/snippets/unfold.md b/snippets/unfold.md new file mode 100644 index 000000000..ff161aa91 --- /dev/null +++ b/snippets/unfold.md @@ -0,0 +1,20 @@ +### unfold + +Builds an array, using an iterator function and an initial seed value. + +Use a `while` loop and `Array.push()` to call the function repeatedly until it returns `false`. +The iterator function accepts one argument (`seed`) and must always return an array with two elements ([`value`, `nextSeed`]) or `false` to terminate. + +```js +const unfold = (fn, seed) => { + let result = [], + val = [null, seed]; + while ((val = fn(val[1]))) result.push(val[0]); + return result; +}; +``` + +```js +var f = n => (n > 50 ? false : [-n, n + 10]); +unfold(f, 10); // [-10, -20, -30, -40, -50] +``` diff --git a/snippets/unionBy.md b/snippets/unionBy.md new file mode 100644 index 000000000..3680c6d1c --- /dev/null +++ b/snippets/unionBy.md @@ -0,0 +1,18 @@ +### unionBy + +Returns every element that exists in any of the two arrays once, after applying the provided function to each array element of both. + +Create a `Set` by applying all `fn` to all values of `a`. +Create a `Set` from `a` and all elements in `b` whose value, after applying `fn` does not match a value in the previously created set. +Return the last set converted to an array. + +```js +const unionBy = (a, b, fn) => { + const s = new Set(a.map(v => fn(v))); + return Array.from(new Set([...a, ...b.filter(x => !s.has(fn(x)))])); +}; +``` + +```js +unionBy([2.1], [1.2, 2.3], Math.floor); // [2.1, 1.2] +``` diff --git a/snippets/unionWith.md b/snippets/unionWith.md new file mode 100644 index 000000000..0243a12aa --- /dev/null +++ b/snippets/unionWith.md @@ -0,0 +1,14 @@ +### unionWith + +Returns every element that exists in any of the two arrays once, using a provided comparator function. + +Create a `Set` with all values of `a` and values in `b` for which the comparator finds no matches in `a`, using `Array.findIndex()`. + +```js +const unionWith = (a, b, comp) => + Array.from(new Set([...a, ...b.filter(x => a.findIndex(y => comp(x, y)) === -1)])); +``` + +```js +unionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)); // [1, 1.2, 1.5, 3, 0, 3.9] +``` diff --git a/snippets/unzip.md b/snippets/unzip.md new file mode 100644 index 000000000..96503871e --- /dev/null +++ b/snippets/unzip.md @@ -0,0 +1,21 @@ +### unzip + +Creates an array of arrays, ungrouping the elements in an array produced by [zip](#zip). + +Use `Math.max.apply()` to get the longest subarray in the array, `Array.map()` to make each element an array. +Use `Array.reduce()` and `Array.forEach()` to map grouped values to individual arrays. + +```js +const unzip = arr => + arr.reduce( + (acc, val) => (val.forEach((v, i) => acc[i].push(v)), acc), + Array.from({ + length: Math.max(...arr.map(x => x.length)) + }).map(x => []) + ); +``` + +```js +unzip([['a', 1, true], ['b', 2, false]]); //[['a', 'b'], [1, 2], [true, false]] +unzip([['a', 1, true], ['b', 2]]); //[['a', 'b'], [1, 2], [true]] +``` diff --git a/snippets/unzipWith.md b/snippets/unzipWith.md new file mode 100644 index 000000000..c474a2e84 --- /dev/null +++ b/snippets/unzipWith.md @@ -0,0 +1,23 @@ +### unzipWith + +Creates an array of elements, ungrouping the elements in an array produced by [zip](#zip) and applying the provided function. + +Use `Math.max.apply()` to get the longest subarray in the array, `Array.map()` to make each element an array. +Use `Array.reduce()` and `Array.forEach()` to map grouped values to individual arrays. +Use `Array.map()` and the spread operator (`...`) to apply `fn` to each individual group of elements. + +```js +const unzipWith = (arr, fn) => + arr + .reduce( + (acc, val) => (val.forEach((v, i) => acc[i].push(v)), acc), + Array.from({ + length: Math.max(...arr.map(x => x.length)) + }).map(x => []) + ) + .map(val => fn(...val)); +``` + +```js +unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0)); // [3, 30, 300] +``` diff --git a/snippets/xProd.md b/snippets/xProd.md new file mode 100644 index 000000000..df1bd897a --- /dev/null +++ b/snippets/xProd.md @@ -0,0 +1,13 @@ +### xProd + +Creates a new array out of the two supplied by creating each possible pair from the arrays. + +Use `Array.reduce()`, `Array.map()` and `Array.concat()` to produce every possible pair from the elements of the two arrays and save them in an array. + +```js +const xProd = (a, b) => a.reduce((acc, x) => acc.concat(b.map(y => [x, y])), []); +``` + +```js +xProd([1, 2], ['a', 'b']); // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] +``` diff --git a/snippets/zipWith.md b/snippets/zipWith.md new file mode 100644 index 000000000..55b6dd446 --- /dev/null +++ b/snippets/zipWith.md @@ -0,0 +1,32 @@ +### zipWith + +Creates an array of elements, grouped based on the position in the original arrays and using function as the last value to specify how grouped values should be combined. + +Check if the last argument provided in a function. +Use `Math.max()` to get the longest array in the arguments. +Creates an array with that length as return value and use `Array.from()` with a map-function to create an array of grouped elements. +If lengths of the argument-arrays vary, `undefined` is used where no value could be found. +The function is invoked with the elements of each group `(...group)`. + +```js +const zipWith = (...arrays) => { + const length = arrays.length; + let fn = length > 1 ? arrays[length - 1] : undefined; + fn = typeof fn == 'function' ? (arrays.pop(), fn) : undefined; + const maxLength = Math.max(...arrays.map(x => x.length)); + const result = Array.from({ length: maxLength }).map((_, i) => { + return Array.from({ length: arrays.length }, (_, k) => arrays[k][i]); + }); + return fn ? result.map(arr => fn(...arr)) : result; +}; +``` + +```js +zipWith([1, 2], [10, 20], [100, 200], (a, b, c) => a + b + c); // [111,222] +zipWith( + [1, 2, 3], + [10, 20], + [100, 200], + (a, b, c) => (a != null ? a : 'a') + (b != null ? b : 'b') + (c != null ? c : 'c') +); // [111, 222, '3bc'] +``` diff --git a/snippets_archive/README.md b/snippets_archive/README.md index e51a9be23..bd8901939 100644 --- a/snippets_archive/README.md +++ b/snippets_archive/README.md @@ -9,18 +9,19 @@ These snippets, while useful and interesting, didn't quite make it into the repo * [`JSONToDate`](#jsontodate) * [`speechSynthesis`](#speechsynthesis) * [`binarySearch`](#binarysearch) +* [`cleanObj`](#cleanobj) * [`collatz`](#collatz) * [`countVowels`](#countvowels) * [`factors`](#factors) * [`fibonacciCountUntilNum`](#fibonaccicountuntilnum) -* [`fibonacciUntilNum`](#fibonacciuntilnum) +* [`howManyTimes`](#howmanytimes) * [`httpDelete`](#httpdelete) * [`httpPut`](#httpput) * [`isArmstrongNumber`](#isarmstrongnumber) * [`quickSort`](#quicksort) * [`removeVowels`](#removevowels) * [`solveRPN`](#solverpn) -* [`howManyTimes`](#howmanytimes) +* [`fibonacciUntilNum`](#fibonacciuntilnum) --- @@ -111,6 +112,39 @@ binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 21); // -1
[⬆ Back to top](#table-of-contents) +### cleanObj + +Removes any properties except the ones specified from a JSON object. + +Use `Object.keys()` method to loop over given JSON object and deleting keys that are not included in given array. +If you pass a special key,`childIndicator`, it will search deeply apply the function to inner objects, too. + +```js +const cleanObj = (obj, keysToKeep = [], childIndicator) => { + Object.keys(obj).forEach(key => { + if (key === childIndicator) { + cleanObj(obj[key], keysToKeep, childIndicator); + } else if (!keysToKeep.includes(key)) { + delete obj[key]; + } + }); + return obj; +}; +``` + +++ +Examples
+ +```js +const testObj = { a: 1, b: 2, children: { a: 1, b: 2 } }; +cleanObj(testObj, ['a'], 'children'); // { a: 1, children : { a: 1}} +``` + +
[⬆ Back to top](#table-of-contents) + + ### collatz Applies the Collatz algorithm. @@ -230,21 +264,26 @@ fibonacciCountUntilNum(10); // 7
[⬆ Back to top](#table-of-contents) -### fibonacciUntilNum +### howManyTimes -Generates an array, containing the Fibonacci sequence, up until the nth term. +Returns the number of times `num` can be divided by `divisor` (integer or fractional) without getting a fractional answer. +Works for both negative and positive integers. -Create an empty array of the specific length, initializing the first two values (`0` and `1`). -Use `Array.reduce()` to add values into the array, using the sum of the last two values, except for the first two. -Uses a mathematical formula to calculate the length of the array required. +If `divisor` is `-1` or `1` return `Infinity`. +If `divisor` is `-0` or `0` return `0`. +Otherwise, keep dividing `num` with `divisor` and incrementing `i`, while the result is an integer. +Return the number of times the loop was executed, `i`. ```js -const fibonacciUntilNum = num => { - let n = Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2)); - return Array.from({ length: n }).reduce( - (acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i), - [] - ); +const howManyTimes = (num, divisor) => { + if (divisor === 1 || divisor === -1) return Infinity; + if (divisor === 0) return 0; + let i = 0; + while (Number.isInteger(num / divisor)) { + i++; + num = num / divisor; + } + return i; }; ``` @@ -252,7 +291,10 @@ const fibonacciUntilNum = num => {Examples
```js -fibonacciUntilNum(10); // [ 0, 1, 1, 2, 3, 5, 8 ] +howManyTimes(100, 2); // 2 +howManyTimes(100, 2.5); // 2 +howManyTimes(100, 0); // 0 +howManyTimes(100, -1); // Infinity ``` @@ -466,26 +508,21 @@ solveRPN('2 3 ^'); // 8
[⬆ Back to top](#table-of-contents) -### howManyTimes +### fibonacciUntilNum -Returns the number of times `num` can be divided by `divisor` (integer or fractional) without getting a fractional answer. -Works for both negative and positive integers. +Generates an array, containing the Fibonacci sequence, up until the nth term. -If `divisor` is `-1` or `1` return `Infinity`. -If `divisor` is `-0` or `0` return `0`. -Otherwise, keep dividing `num` with `divisor` and incrementing `i`, while the result is an integer. -Return the number of times the loop was executed, `i`. +Create an empty array of the specific length, initializing the first two values (`0` and `1`). +Use `Array.reduce()` to add values into the array, using the sum of the last two values, except for the first two. +Uses a mathematical formula to calculate the length of the array required. ```js -const howManyTimes = (num, divisor) => { - if (divisor === 1 || divisor === -1) return Infinity; - if (divisor === 0) return 0; - let i = 0; - while (Number.isInteger(num / divisor)) { - i++; - num = num / divisor; - } - return i; +const fibonacciUntilNum = num => { + let n = Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2)); + return Array.from({ length: n }).reduce( + (acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i), + [] + ); }; ``` @@ -493,10 +530,7 @@ const howManyTimes = (num, divisor) => {Examples
```js -howManyTimes(100, 2); // 2 -howManyTimes(100, 2.5); // 2 -howManyTimes(100, 0); // 0 -howManyTimes(100, -1); // Infinity +fibonacciUntilNum(10); // [ 0, 1, 1, 2, 3, 5, 8 ] ``` diff --git a/tag_database b/tag_database index d1cd81502..80db02651 100644 --- a/tag_database +++ b/tag_database @@ -1,14 +1,18 @@ anagrams:string,recursion arrayToHtmlList:browser,array +ary:adapter,function atob:node,string,utility average:math,array averageBy:math,array,function +bind:function,object +bindKey:function,object bottomVisible:browser btoa:node,string,utility byteSize:string call:adapter,function capitalize:string,array capitalizeEveryWord:string,regexp +castArray:utility,array,type chainAsync:function chunk:array clampNumber:math @@ -19,6 +23,7 @@ collectInto:adapter,function,array colorize:node,utility,string compact:array compose:function +composeRight:function copyToClipboard:browser,string,advanced countBy:array,object countOccurrences:array @@ -27,11 +32,14 @@ createEventHub:browser,event,advanced currentURL:browser,url curry:function,recursion decapitalize:string,array +deepClone:object,recursion deepFlatten:array,recursion defaults:object defer:function +delay:function detectDeviceType:browser difference:array,math +differenceBy:array,function differenceWith:array,function digitize:math,array distance:math @@ -47,7 +55,10 @@ extendHex:utility,string factorial:math,recursion fibonacci:math,array filterNonUnique:array +findKey:object,function findLast:array +findLastIndex:array,function +findLastKey:object,function flatten:array flip:adapter,function forEachRight:array,function @@ -85,12 +96,15 @@ initializeArrayWithRangeRight:array,math initializeArrayWithValues:array,math inRange:math intersection:array,math -invertKeyValues:object +intersectionBy:array,function +intersectionWith:array,function +invertKeyValues:object,function is:type,array,regexp isAbsoluteURL:string,utility,browser,url isArrayLike:type,array isBoolean:type isDivisible:math +isEmpty:type,array,object,string isEven:math isFunction:type,function isLowerCase:string,utility @@ -98,6 +112,7 @@ isNil:type isNull:type isNumber:type,math isObject:type,object +isObjectLike:type,object isPlainObject:type,object isPrime:math isPrimitive:type,function,array,string @@ -120,6 +135,8 @@ mapKeys:object,function mapObject:array,object mapValues:object,function mask:string,utility,regexp +matches:object,type +matchesWith:object,type,function maxBy:math,array,function maxN:array,math median:math,array @@ -128,6 +145,7 @@ merge:object,array minBy:math,array,function minN:array,math negate:function +nthArg:utility,function nthElement:array objectFromPairs:object,array objectToPairs:object,array @@ -139,8 +157,11 @@ on:browser,event once:function onUserInputChange:browser,event,advanced orderBy:object,array +over:adapter,function palindrome:string parseCookie:utility,string +partial:function +partialRight:function partition:array,object,function percentile:math pick:object,array @@ -161,6 +182,8 @@ randomNumberInRange:math,utility,random readFileLines:node,array,string redirect:browser,url reducedFilter:array +reduceSuccessive:array,function +reduceWhich:array,function remove:array reverseString:string,array RGBToHex:utility @@ -181,6 +204,7 @@ size:object,array,string sleep:function,promise sortCharactersInString:string sortedIndex:array,math +sortedLastIndex:array,math splitLines:string spreadOver:adapter standardDeviation:math,array @@ -188,9 +212,12 @@ sum:math,array sumBy:math,array,function sumPower:math symmetricDifference:array,math +symmetricDifferenceBy:array,function +symmetricDifferenceWith:array,function tail:array take:array takeRight:array +times:function timeTaken:utility toCamelCase:string,regexp toDecimalMark:utility,math @@ -203,16 +230,24 @@ toSnakeCase:string,regexp transform:object,array truncateString:string truthCheckCollection:object,logic,array +unary:adapter,function unescapeHTML:string,browser +unfold:function,array union:array,math +unionBy:array,function +unionWith:array,function uniqueElements:array untildify:node,string +unzip:array +unzipWith:array,function,advanced URLJoin:string,utility,regexp UUIDGeneratorBrowser:browser,utility,random UUIDGeneratorNode:node,utility,random validateNumber:utility,math without:array words:string,regexp +xProd:array,math yesNo:utility,regexp zip:array zipObject:array,object +zipWith:array,advanced diff --git a/test/JSONToDate/JSONToDate.js b/test/JSONToDate/JSONToDate.js index b22d17b2c..658c2f6fc 100644 --- a/test/JSONToDate/JSONToDate.js +++ b/test/JSONToDate/JSONToDate.js @@ -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 \ No newline at end of file +module.exports = JSONToDate \ No newline at end of file diff --git a/test/JSONToDate/JSONToDate.test.js b/test/JSONToDate/JSONToDate.test.js index 9636880ac..1e2a7a57b 100644 --- a/test/JSONToDate/JSONToDate.test.js +++ b/test/JSONToDate/JSONToDate.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const JSONToDate = require('./JSONToDate.js'); test('Testing JSONToDate', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof JSONToDate === 'function', 'JSONToDate is a Function'); - //t.deepEqual(JSONToDate(args..), 'Expected'); - //t.equal(JSONToDate(args..), 'Expected'); - //t.false(JSONToDate(args..), 'Expected'); - //t.throws(JSONToDate(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof JSONToDate === 'function', 'JSONToDate is a Function'); + //t.deepEqual(JSONToDate(args..), 'Expected'); + //t.equal(JSONToDate(args..), 'Expected'); + //t.false(JSONToDate(args..), 'Expected'); + //t.throws(JSONToDate(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/JSONToFile/JSONToFile.js b/test/JSONToFile/JSONToFile.js index 695fd5ecd..450fe0d35 100644 --- a/test/JSONToFile/JSONToFile.js +++ b/test/JSONToFile/JSONToFile.js @@ -1,4 +1,4 @@ const fs = require('fs'); const JSONToFile = (obj, filename) => fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2)); - module.exports = JSONToFile \ No newline at end of file +module.exports = JSONToFile \ No newline at end of file diff --git a/test/JSONToFile/JSONToFile.test.js b/test/JSONToFile/JSONToFile.test.js index 7dbfeaf94..47bccf60b 100644 --- a/test/JSONToFile/JSONToFile.test.js +++ b/test/JSONToFile/JSONToFile.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const JSONToFile = require('./JSONToFile.js'); test('Testing JSONToFile', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof JSONToFile === 'function', 'JSONToFile is a Function'); - //t.deepEqual(JSONToFile(args..), 'Expected'); - //t.equal(JSONToFile(args..), 'Expected'); - //t.false(JSONToFile(args..), 'Expected'); - //t.throws(JSONToFile(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof JSONToFile === 'function', 'JSONToFile is a Function'); + //t.deepEqual(JSONToFile(args..), 'Expected'); + //t.equal(JSONToFile(args..), 'Expected'); + //t.false(JSONToFile(args..), 'Expected'); + //t.throws(JSONToFile(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/README/README.test.js b/test/README/README.test.js index bfbab3850..7ae30976a 100644 --- a/test/README/README.test.js +++ b/test/README/README.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const README = require('./README.js'); test('Testing README', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof README === 'function', 'README is a Function'); - //t.deepEqual(README(args..), 'Expected'); - //t.equal(README(args..), 'Expected'); - //t.false(README(args..), 'Expected'); - //t.throws(README(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof README === 'function', 'README is a Function'); + //t.deepEqual(README(args..), 'Expected'); + //t.equal(README(args..), 'Expected'); + //t.false(README(args..), 'Expected'); + //t.throws(README(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/RGBToHex/RGBToHex.js b/test/RGBToHex/RGBToHex.js index 1caaf7cd4..4e84c450b 100644 --- a/test/RGBToHex/RGBToHex.js +++ b/test/RGBToHex/RGBToHex.js @@ -1,2 +1,2 @@ const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0'); - module.exports = RGBToHex \ No newline at end of file +module.exports = RGBToHex \ No newline at end of file diff --git a/test/RGBToHex/RGBToHex.test.js b/test/RGBToHex/RGBToHex.test.js index 4407ff564..277d6575c 100644 --- a/test/RGBToHex/RGBToHex.test.js +++ b/test/RGBToHex/RGBToHex.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const RGBToHex = require('./RGBToHex.js'); test('Testing RGBToHex', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof RGBToHex === 'function', 'RGBToHex is a Function'); - t.equal(RGBToHex(255, 165, 1), 'ffa501', "Converts the values of RGB components to a color code."); - //t.deepEqual(RGBToHex(args..), 'Expected'); - //t.equal(RGBToHex(args..), 'Expected'); - //t.false(RGBToHex(args..), 'Expected'); - //t.throws(RGBToHex(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof RGBToHex === 'function', 'RGBToHex is a Function'); + t.equal(RGBToHex(255, 165, 1), 'ffa501', "Converts the values of RGB components to a color code."); + //t.deepEqual(RGBToHex(args..), 'Expected'); + //t.equal(RGBToHex(args..), 'Expected'); + //t.false(RGBToHex(args..), 'Expected'); + //t.throws(RGBToHex(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/URLJoin/URLJoin.js b/test/URLJoin/URLJoin.js index 0ba1bad9a..ccff1cb75 100644 --- a/test/URLJoin/URLJoin.js +++ b/test/URLJoin/URLJoin.js @@ -7,4 +7,4 @@ args .replace(/\/(\?|&|#[^!])/g, '$1') .replace(/\?/g, '&') .replace('&', '?'); - module.exports = URLJoin \ No newline at end of file +module.exports = URLJoin \ No newline at end of file diff --git a/test/URLJoin/URLJoin.test.js b/test/URLJoin/URLJoin.test.js index 17f567d39..70d0d09a6 100644 --- a/test/URLJoin/URLJoin.test.js +++ b/test/URLJoin/URLJoin.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const URLJoin = require('./URLJoin.js'); test('Testing URLJoin', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof URLJoin === 'function', 'URLJoin is a Function'); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof URLJoin === 'function', 'URLJoin is a Function'); t.equal(URLJoin('http://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo'), 'http://www.google.com/a/b/cd?foo=123&bar=foo', 'Returns proper URL'); t.equal(URLJoin('file://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo'), 'file:///www.google.com/a/b/cd?foo=123&bar=foo', 'Returns proper URL'); - //t.deepEqual(URLJoin(args..), 'Expected'); - //t.equal(URLJoin(args..), 'Expected'); - //t.false(URLJoin(args..), 'Expected'); - //t.throws(URLJoin(args..), 'Expected'); - t.end(); + //t.deepEqual(URLJoin(args..), 'Expected'); + //t.equal(URLJoin(args..), 'Expected'); + //t.false(URLJoin(args..), 'Expected'); + //t.throws(URLJoin(args..), 'Expected'); + t.end(); }); diff --git a/test/UUIDGeneratorBrowser/UUIDGeneratorBrowser.js b/test/UUIDGeneratorBrowser/UUIDGeneratorBrowser.js index 78f421fef..bdd30d1f1 100644 --- a/test/UUIDGeneratorBrowser/UUIDGeneratorBrowser.js +++ b/test/UUIDGeneratorBrowser/UUIDGeneratorBrowser.js @@ -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 \ No newline at end of file +module.exports = UUIDGeneratorBrowser \ No newline at end of file diff --git a/test/UUIDGeneratorBrowser/UUIDGeneratorBrowser.test.js b/test/UUIDGeneratorBrowser/UUIDGeneratorBrowser.test.js index d6f5407a4..bb868d1e8 100644 --- a/test/UUIDGeneratorBrowser/UUIDGeneratorBrowser.test.js +++ b/test/UUIDGeneratorBrowser/UUIDGeneratorBrowser.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const UUIDGeneratorBrowser = require('./UUIDGeneratorBrowser.js'); test('Testing UUIDGeneratorBrowser', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof UUIDGeneratorBrowser === 'function', 'UUIDGeneratorBrowser is a Function'); - //t.deepEqual(UUIDGeneratorBrowser(args..), 'Expected'); - //t.equal(UUIDGeneratorBrowser(args..), 'Expected'); - //t.false(UUIDGeneratorBrowser(args..), 'Expected'); - //t.throws(UUIDGeneratorBrowser(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof UUIDGeneratorBrowser === 'function', 'UUIDGeneratorBrowser is a Function'); + //t.deepEqual(UUIDGeneratorBrowser(args..), 'Expected'); + //t.equal(UUIDGeneratorBrowser(args..), 'Expected'); + //t.false(UUIDGeneratorBrowser(args..), 'Expected'); + //t.throws(UUIDGeneratorBrowser(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/UUIDGeneratorNode/UUIDGeneratorNode.js b/test/UUIDGeneratorNode/UUIDGeneratorNode.js index 956d887c3..46afbd090 100644 --- a/test/UUIDGeneratorNode/UUIDGeneratorNode.js +++ b/test/UUIDGeneratorNode/UUIDGeneratorNode.js @@ -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 \ No newline at end of file +module.exports = UUIDGeneratorNode \ No newline at end of file diff --git a/test/UUIDGeneratorNode/UUIDGeneratorNode.test.js b/test/UUIDGeneratorNode/UUIDGeneratorNode.test.js index 44b7040e1..bedb41340 100644 --- a/test/UUIDGeneratorNode/UUIDGeneratorNode.test.js +++ b/test/UUIDGeneratorNode/UUIDGeneratorNode.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const UUIDGeneratorNode = require('./UUIDGeneratorNode.js'); test('Testing UUIDGeneratorNode', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof UUIDGeneratorNode === 'function', 'UUIDGeneratorNode is a Function'); - //t.deepEqual(UUIDGeneratorNode(args..), 'Expected'); - //t.equal(UUIDGeneratorNode(args..), 'Expected'); - //t.false(UUIDGeneratorNode(args..), 'Expected'); - //t.throws(UUIDGeneratorNode(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof UUIDGeneratorNode === 'function', 'UUIDGeneratorNode is a Function'); + //t.deepEqual(UUIDGeneratorNode(args..), 'Expected'); + //t.equal(UUIDGeneratorNode(args..), 'Expected'); + //t.false(UUIDGeneratorNode(args..), 'Expected'); + //t.throws(UUIDGeneratorNode(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/anagrams/anagrams.js b/test/anagrams/anagrams.js index 2b31ca520..32a1b62ae 100644 --- a/test/anagrams/anagrams.js +++ b/test/anagrams/anagrams.js @@ -8,4 +8,4 @@ acc.concat(anagrams(str.slice(0, i) + str.slice(i + 1)).map(val => letter + val) [] ); }; - module.exports = anagrams \ No newline at end of file +module.exports = anagrams \ No newline at end of file diff --git a/test/anagrams/anagrams.test.js b/test/anagrams/anagrams.test.js index 8368a91a8..4318f4c46 100644 --- a/test/anagrams/anagrams.test.js +++ b/test/anagrams/anagrams.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const anagrams = require('./anagrams.js'); test('Testing anagrams', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof anagrams === 'function', 'anagrams is a Function'); - t.deepEqual(anagrams('abc'), ['abc','acb','bac','bca','cab','cba'], "Generates all anagrams of a string"); - //t.deepEqual(anagrams(args..), 'Expected'); - //t.equal(anagrams(args..), 'Expected'); - //t.false(anagrams(args..), 'Expected'); - //t.throws(anagrams(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof anagrams === 'function', 'anagrams is a Function'); + t.deepEqual(anagrams('abc'), ['abc','acb','bac','bca','cab','cba'], "Generates all anagrams of a string"); + //t.deepEqual(anagrams(args..), 'Expected'); + //t.equal(anagrams(args..), 'Expected'); + //t.false(anagrams(args..), 'Expected'); + //t.throws(anagrams(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/arrayToHtmlList/arrayToHtmlList.js b/test/arrayToHtmlList/arrayToHtmlList.js index e85f273e7..ae6fed9c2 100644 --- a/test/arrayToHtmlList/arrayToHtmlList.js +++ b/test/arrayToHtmlList/arrayToHtmlList.js @@ -1,3 +1,3 @@ const arrayToHtmlList = (arr, listID) => arr.map(item => (document.querySelector('#' + listID).innerHTML += `${item} `)); - module.exports = arrayToHtmlList \ No newline at end of file +module.exports = arrayToHtmlList \ No newline at end of file diff --git a/test/arrayToHtmlList/arrayToHtmlList.test.js b/test/arrayToHtmlList/arrayToHtmlList.test.js index b4a4b036b..1f8885778 100644 --- a/test/arrayToHtmlList/arrayToHtmlList.test.js +++ b/test/arrayToHtmlList/arrayToHtmlList.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const arrayToHtmlList = require('./arrayToHtmlList.js'); test('Testing arrayToHtmlList', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof arrayToHtmlList === 'function', 'arrayToHtmlList is a Function'); - //t.deepEqual(arrayToHtmlList(args..), 'Expected'); - //t.equal(arrayToHtmlList(args..), 'Expected'); - //t.false(arrayToHtmlList(args..), 'Expected'); - //t.throws(arrayToHtmlList(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof arrayToHtmlList === 'function', 'arrayToHtmlList is a Function'); + //t.deepEqual(arrayToHtmlList(args..), 'Expected'); + //t.equal(arrayToHtmlList(args..), 'Expected'); + //t.false(arrayToHtmlList(args..), 'Expected'); + //t.throws(arrayToHtmlList(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/ary/ary.js b/test/ary/ary.js new file mode 100644 index 000000000..25aa3b39a --- /dev/null +++ b/test/ary/ary.js @@ -0,0 +1,2 @@ +const ary = (fn, n) => (...args) => fn(...args.slice(0, n)); +module.exports = ary \ No newline at end of file diff --git a/test/ary/ary.test.js b/test/ary/ary.test.js new file mode 100644 index 000000000..445b40618 --- /dev/null +++ b/test/ary/ary.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const ary = require('./ary.js'); + +test('Testing ary', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof ary === 'function', 'ary is a Function'); + //t.deepEqual(ary(args..), 'Expected'); + //t.equal(ary(args..), 'Expected'); + //t.false(ary(args..), 'Expected'); + //t.throws(ary(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/atob/atob.js b/test/atob/atob.js index 74b526ccd..fc39b89f8 100644 --- a/test/atob/atob.js +++ b/test/atob/atob.js @@ -1,2 +1,2 @@ const atob = str => new Buffer(str, 'base64').toString('binary'); - module.exports = atob \ No newline at end of file +module.exports = atob \ No newline at end of file diff --git a/test/atob/atob.test.js b/test/atob/atob.test.js index 07862e9a2..32e3567d5 100644 --- a/test/atob/atob.test.js +++ b/test/atob/atob.test.js @@ -2,12 +2,14 @@ const test = require('tape'); const atob = require('./atob.js'); test('Testing atob', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof atob === 'function', 'atob is a Function'); - //t.deepEqual(atob(args..), 'Expected'); - //t.equal(atob(args..), 'Expected'); - //t.false(atob(args..), 'Expected'); - //t.throws(atob(args..), 'Expected'); - t.end(); -}); \ No newline at end of file + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof atob === 'function', 'atob is a Function'); + t.equals(atob('Zm9vYmFy'), 'foobar', 'atob("Zm9vYmFy") equals "foobar"'); + t.equals(atob('Z'), '', 'atob("Z") returns ""'); + //t.deepEqual(atob(args..), 'Expected'); + //t.equal(atob(args..), 'Expected'); + //t.false(atob(args..), 'Expected'); + //t.throws(atob(args..), 'Expected'); + t.end(); +}); diff --git a/test/average/average.js b/test/average/average.js index 4f414ff98..57c11529f 100644 --- a/test/average/average.js +++ b/test/average/average.js @@ -1,2 +1,2 @@ const average = (...nums) => [...nums].reduce((acc, val) => acc + val, 0) / nums.length; - module.exports = average \ No newline at end of file +module.exports = average \ No newline at end of file diff --git a/test/average/average.test.js b/test/average/average.test.js index c38a2ee5c..dff7df5a7 100644 --- a/test/average/average.test.js +++ b/test/average/average.test.js @@ -2,23 +2,23 @@ const test = require('tape'); const average = require('./average.js'); test('Testing average', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape t.true(typeof average === 'function', 'average is a Function'); t.true(average(true) === 1, 'average(true) returns 0'); t.true(average(false) === 0, 'average(false) returns 1'); t.equal(average(9, 1), 5, 'average(9, 1) returns 5'); - t.equal(average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631), 32163.909090909092, 'average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631) returns 32163.909090909092 '); - t.equal(average(1, 2, 3), 2, 'average(1, 2, 3) returns 2'); + t.equal(average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631), 32163.909090909092, 'average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631) returns 32163.909090909092 '); + t.equal(average(1, 2, 3), 2, 'average(1, 2, 3) returns 2'); t.equal(average(null), 0, 'average(null) returns 0'); - t.true(isNaN(average(undefined)), 'average(1, 2, 3) returns NaN'); - t.true(isNaN(average('String')), 'average(String) returns NaN'); - t.true(isNaN(average({ a: 123})), 'average({ a: 123}) returns NaN'); - t.true(isNaN(average([undefined, 0, 'string'])), 'average([undefined, 0, string]) returns NaN'); + t.true(isNaN(average(undefined)), 'average(1, 2, 3) returns NaN'); + t.true(isNaN(average('String')), 'average(String) returns NaN'); + t.true(isNaN(average({ a: 123})), 'average({ a: 123}) returns NaN'); + t.true(isNaN(average([undefined, 0, 'string'])), 'average([undefined, 0, string]) returns NaN'); let start = new Date().getTime(); average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631); let end = new Date().getTime(); t.true((end - start) < 2000, 'head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run'); - t.end(); + t.end(); }); \ No newline at end of file diff --git a/test/averageBy/averageBy.js b/test/averageBy/averageBy.js index 5e8bb3a27..fc38bc749 100644 --- a/test/averageBy/averageBy.js +++ b/test/averageBy/averageBy.js @@ -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 \ No newline at end of file +module.exports = averageBy \ No newline at end of file diff --git a/test/averageBy/averageBy.test.js b/test/averageBy/averageBy.test.js index 60675dfb7..7c3fabe16 100644 --- a/test/averageBy/averageBy.test.js +++ b/test/averageBy/averageBy.test.js @@ -2,12 +2,14 @@ const test = require('tape'); const averageBy = require('./averageBy.js'); test('Testing averageBy', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof averageBy === 'function', 'averageBy is a Function'); - //t.deepEqual(averageBy(args..), 'Expected'); - //t.equal(averageBy(args..), 'Expected'); - //t.false(averageBy(args..), 'Expected'); - //t.throws(averageBy(args..), 'Expected'); - t.end(); -}); \ No newline at end of file + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof averageBy === 'function', 'averageBy is a Function'); + t.equals(averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n), 5, 'Produces the right result with a function'); + t.equals(averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'), 5, 'Produces the right result with a property name'); + //t.deepEqual(averageBy(args..), 'Expected'); + //t.equal(averageBy(args..), 'Expected'); + //t.false(averageBy(args..), 'Expected'); + //t.throws(averageBy(args..), 'Expected'); + t.end(); +}); diff --git a/test/binarySearch/binarySearch.js b/test/binarySearch/binarySearch.js index b34d667bf..484a20638 100644 --- a/test/binarySearch/binarySearch.js +++ b/test/binarySearch/binarySearch.js @@ -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 \ No newline at end of file +module.exports = binarySearch \ No newline at end of file diff --git a/test/binarySearch/binarySearch.test.js b/test/binarySearch/binarySearch.test.js index 754a31ad6..a98fc8e90 100644 --- a/test/binarySearch/binarySearch.test.js +++ b/test/binarySearch/binarySearch.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const binarySearch = require('./binarySearch.js'); test('Testing binarySearch', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof binarySearch === 'function', 'binarySearch is a Function'); - //t.deepEqual(binarySearch(args..), 'Expected'); - //t.equal(binarySearch(args..), 'Expected'); - //t.false(binarySearch(args..), 'Expected'); - //t.throws(binarySearch(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof binarySearch === 'function', 'binarySearch is a Function'); + //t.deepEqual(binarySearch(args..), 'Expected'); + //t.equal(binarySearch(args..), 'Expected'); + //t.false(binarySearch(args..), 'Expected'); + //t.throws(binarySearch(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/bind/bind.js b/test/bind/bind.js new file mode 100644 index 000000000..63499a7d0 --- /dev/null +++ b/test/bind/bind.js @@ -0,0 +1,5 @@ +const bind = (fn, context, ...args) => +function() { +return fn.apply(context, args.concat(...arguments)); +}; +module.exports = bind \ No newline at end of file diff --git a/test/bind/bind.test.js b/test/bind/bind.test.js new file mode 100644 index 000000000..6ad403682 --- /dev/null +++ b/test/bind/bind.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const bind = require('./bind.js'); + +test('Testing bind', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof bind === 'function', 'bind is a Function'); + //t.deepEqual(bind(args..), 'Expected'); + //t.equal(bind(args..), 'Expected'); + //t.false(bind(args..), 'Expected'); + //t.throws(bind(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/bindKey/bindKey.js b/test/bindKey/bindKey.js new file mode 100644 index 000000000..72d491b73 --- /dev/null +++ b/test/bindKey/bindKey.js @@ -0,0 +1,5 @@ +const bindKey = (context, fn, ...args) => +function() { +return context[fn].apply(context, args.concat(...arguments)); +}; +module.exports = bindKey \ No newline at end of file diff --git a/test/bindKey/bindKey.test.js b/test/bindKey/bindKey.test.js new file mode 100644 index 000000000..36619ebcd --- /dev/null +++ b/test/bindKey/bindKey.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const bindKey = require('./bindKey.js'); + +test('Testing bindKey', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof bindKey === 'function', 'bindKey is a Function'); + //t.deepEqual(bindKey(args..), 'Expected'); + //t.equal(bindKey(args..), 'Expected'); + //t.false(bindKey(args..), 'Expected'); + //t.throws(bindKey(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/bottomVisible/bottomVisible.js b/test/bottomVisible/bottomVisible.js index abf32b046..68c5f357c 100644 --- a/test/bottomVisible/bottomVisible.js +++ b/test/bottomVisible/bottomVisible.js @@ -1,4 +1,4 @@ const bottomVisible = () => document.documentElement.clientHeight + window.scrollY >= (document.documentElement.scrollHeight || document.documentElement.clientHeight); - module.exports = bottomVisible \ No newline at end of file +module.exports = bottomVisible \ No newline at end of file diff --git a/test/bottomVisible/bottomVisible.test.js b/test/bottomVisible/bottomVisible.test.js index be6f6871b..1c8eae4be 100644 --- a/test/bottomVisible/bottomVisible.test.js +++ b/test/bottomVisible/bottomVisible.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const bottomVisible = require('./bottomVisible.js'); test('Testing bottomVisible', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof bottomVisible === 'function', 'bottomVisible is a Function'); - //t.deepEqual(bottomVisible(args..), 'Expected'); - //t.equal(bottomVisible(args..), 'Expected'); - //t.false(bottomVisible(args..), 'Expected'); - //t.throws(bottomVisible(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof bottomVisible === 'function', 'bottomVisible is a Function'); + //t.deepEqual(bottomVisible(args..), 'Expected'); + //t.equal(bottomVisible(args..), 'Expected'); + //t.false(bottomVisible(args..), 'Expected'); + //t.throws(bottomVisible(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/btoa/btoa.js b/test/btoa/btoa.js index 4393d4d67..af14ade08 100644 --- a/test/btoa/btoa.js +++ b/test/btoa/btoa.js @@ -1,2 +1,2 @@ const btoa = str => new Buffer(str, 'binary').toString('base64'); - module.exports = btoa \ No newline at end of file +module.exports = btoa \ No newline at end of file diff --git a/test/btoa/btoa.test.js b/test/btoa/btoa.test.js index da0e6a5a3..85690e99b 100644 --- a/test/btoa/btoa.test.js +++ b/test/btoa/btoa.test.js @@ -2,12 +2,13 @@ const test = require('tape'); const btoa = require('./btoa.js'); test('Testing btoa', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof btoa === 'function', 'btoa is a Function'); - //t.deepEqual(btoa(args..), 'Expected'); - //t.equal(btoa(args..), 'Expected'); - //t.false(btoa(args..), 'Expected'); - //t.throws(btoa(args..), 'Expected'); - t.end(); -}); \ No newline at end of file + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof btoa === 'function', 'btoa is a Function'); + t.equals(btoa('foobar'), 'Zm9vYmFy', 'btoa("foobar") equals "Zm9vYmFy"'); + //t.deepEqual(btoa(args..), 'Expected'); + //t.equal(btoa(args..), 'Expected'); + //t.false(btoa(args..), 'Expected'); + //t.throws(btoa(args..), 'Expected'); + t.end(); +}); diff --git a/test/byteSize/byteSize.js b/test/byteSize/byteSize.js index 74a857863..e9ef3735a 100644 --- a/test/byteSize/byteSize.js +++ b/test/byteSize/byteSize.js @@ -1,2 +1,2 @@ const byteSize = str => new Blob([str]).size; - module.exports = byteSize \ No newline at end of file +module.exports = byteSize \ No newline at end of file diff --git a/test/byteSize/byteSize.test.js b/test/byteSize/byteSize.test.js index bac20ac38..32718fada 100644 --- a/test/byteSize/byteSize.test.js +++ b/test/byteSize/byteSize.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const byteSize = require('./byteSize.js'); test('Testing byteSize', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof byteSize === 'function', 'byteSize is a Function'); - // Works only in browser - // t.equal(byteSize('Hello World'), 11, "Returns the length of a string in bytes"); - //t.deepEqual(byteSize(args..), 'Expected'); - //t.equal(byteSize(args..), 'Expected'); - //t.false(byteSize(args..), 'Expected'); - //t.throws(byteSize(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof byteSize === 'function', 'byteSize is a Function'); + // Works only in browser + // t.equal(byteSize('Hello World'), 11, "Returns the length of a string in bytes"); + //t.deepEqual(byteSize(args..), 'Expected'); + //t.equal(byteSize(args..), 'Expected'); + //t.false(byteSize(args..), 'Expected'); + //t.throws(byteSize(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/call/call.js b/test/call/call.js index 660de98a8..bcb7f341b 100644 --- a/test/call/call.js +++ b/test/call/call.js @@ -1,2 +1,2 @@ const call = (key, ...args) => context => context[key](...args); - module.exports = call \ No newline at end of file +module.exports = call \ No newline at end of file diff --git a/test/call/call.test.js b/test/call/call.test.js index f01b61ab1..ba15d452e 100644 --- a/test/call/call.test.js +++ b/test/call/call.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const call = require('./call.js'); test('Testing call', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof call === 'function', 'call is a Function'); - //t.deepEqual(call(args..), 'Expected'); - //t.equal(call(args..), 'Expected'); - //t.false(call(args..), 'Expected'); - //t.throws(call(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof call === 'function', 'call is a Function'); + //t.deepEqual(call(args..), 'Expected'); + //t.equal(call(args..), 'Expected'); + //t.false(call(args..), 'Expected'); + //t.throws(call(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/capitalize/capitalize.js b/test/capitalize/capitalize.js index edd95c811..bc1710773 100644 --- a/test/capitalize/capitalize.js +++ b/test/capitalize/capitalize.js @@ -1,3 +1,3 @@ const capitalize = ([first, ...rest], lowerRest = false) => first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join('')); - module.exports = capitalize \ No newline at end of file +module.exports = capitalize \ No newline at end of file diff --git a/test/capitalize/capitalize.test.js b/test/capitalize/capitalize.test.js index fb8505cfc..75073b934 100644 --- a/test/capitalize/capitalize.test.js +++ b/test/capitalize/capitalize.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const capitalize = require('./capitalize.js'); test('Testing capitalize', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof capitalize === 'function', 'capitalize is a Function'); - t.equal(capitalize('fooBar'), 'FooBar', "Capitalizes the first letter of a string"); - t.equal(capitalize('fooBar', true), 'Foobar', "Capitalizes the first letter of a string"); - //t.deepEqual(capitalize(args..), 'Expected'); - //t.equal(capitalize(args..), 'Expected'); - //t.false(capitalize(args..), 'Expected'); - //t.throws(capitalize(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof capitalize === 'function', 'capitalize is a Function'); + t.equal(capitalize('fooBar'), 'FooBar', "Capitalizes the first letter of a string"); + t.equal(capitalize('fooBar', true), 'Foobar', "Capitalizes the first letter of a string"); + //t.deepEqual(capitalize(args..), 'Expected'); + //t.equal(capitalize(args..), 'Expected'); + //t.false(capitalize(args..), 'Expected'); + //t.throws(capitalize(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/capitalizeEveryWord/capitalizeEveryWord.js b/test/capitalizeEveryWord/capitalizeEveryWord.js index 2bec22dcf..28a8f6d0b 100644 --- a/test/capitalizeEveryWord/capitalizeEveryWord.js +++ b/test/capitalizeEveryWord/capitalizeEveryWord.js @@ -1,2 +1,2 @@ const capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperCase()); - module.exports = capitalizeEveryWord \ No newline at end of file +module.exports = capitalizeEveryWord \ No newline at end of file diff --git a/test/capitalizeEveryWord/capitalizeEveryWord.test.js b/test/capitalizeEveryWord/capitalizeEveryWord.test.js index 783b84631..c4cfc2d54 100644 --- a/test/capitalizeEveryWord/capitalizeEveryWord.test.js +++ b/test/capitalizeEveryWord/capitalizeEveryWord.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const capitalizeEveryWord = require('./capitalizeEveryWord.js'); test('Testing capitalizeEveryWord', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof capitalizeEveryWord === 'function', 'capitalizeEveryWord is a Function'); - t.equal(capitalizeEveryWord('hello world!'), 'Hello World!', "Capitalizes the first letter of every word in a string"); - //t.deepEqual(capitalizeEveryWord(args..), 'Expected'); - //t.equal(capitalizeEveryWord(args..), 'Expected'); - //t.false(capitalizeEveryWord(args..), 'Expected'); - //t.throws(capitalizeEveryWord(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof capitalizeEveryWord === 'function', 'capitalizeEveryWord is a Function'); + t.equal(capitalizeEveryWord('hello world!'), 'Hello World!', "Capitalizes the first letter of every word in a string"); + //t.deepEqual(capitalizeEveryWord(args..), 'Expected'); + //t.equal(capitalizeEveryWord(args..), 'Expected'); + //t.false(capitalizeEveryWord(args..), 'Expected'); + //t.throws(capitalizeEveryWord(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/castArray/castArray.js b/test/castArray/castArray.js new file mode 100644 index 000000000..963203b1f --- /dev/null +++ b/test/castArray/castArray.js @@ -0,0 +1,2 @@ +const castArray = val => (Array.isArray(val) ? val : [val]); +module.exports = castArray \ No newline at end of file diff --git a/test/castArray/castArray.test.js b/test/castArray/castArray.test.js new file mode 100644 index 000000000..a0961a491 --- /dev/null +++ b/test/castArray/castArray.test.js @@ -0,0 +1,18 @@ +const test = require('tape'); +const castArray = require('./castArray.js'); + +test('Testing castArray', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof castArray === 'function', 'castArray is a Function'); + t.deepEqual(castArray(1), [1], 'Works for single values'); + t.deepEqual(castArray([1]), [1], 'Works for arrays with one value'); + t.deepEqual(castArray([1,2,3]), [1,2,3], 'Works for arrays with multiple value'); + t.deepEqual(castArray('test'), ['test'], 'Works for strings'); + t.deepEqual(castArray({}), [{}], 'Works for objects'); + //t.deepEqual(castArray(args..), 'Expected'); + //t.equal(castArray(args..), 'Expected'); + //t.false(castArray(args..), 'Expected'); + //t.throws(castArray(args..), 'Expected'); + t.end(); +}); diff --git a/test/chainAsync/chainAsync.js b/test/chainAsync/chainAsync.js index 4454d477d..8322779ad 100644 --- a/test/chainAsync/chainAsync.js +++ b/test/chainAsync/chainAsync.js @@ -3,4 +3,4 @@ let curr = 0; const next = () => fns[curr++](next); next(); }; - module.exports = chainAsync \ No newline at end of file +module.exports = chainAsync \ No newline at end of file diff --git a/test/chainAsync/chainAsync.test.js b/test/chainAsync/chainAsync.test.js index 9fab8a947..7101ab686 100644 --- a/test/chainAsync/chainAsync.test.js +++ b/test/chainAsync/chainAsync.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const chainAsync = require('./chainAsync.js'); test('Testing chainAsync', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof chainAsync === 'function', 'chainAsync is a Function'); - //t.deepEqual(chainAsync(args..), 'Expected'); - //t.equal(chainAsync(args..), 'Expected'); - //t.false(chainAsync(args..), 'Expected'); - //t.throws(chainAsync(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof chainAsync === 'function', 'chainAsync is a Function'); + //t.deepEqual(chainAsync(args..), 'Expected'); + //t.equal(chainAsync(args..), 'Expected'); + //t.false(chainAsync(args..), 'Expected'); + //t.throws(chainAsync(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/chunk/chunk.js b/test/chunk/chunk.js index 6b27e7f1c..39ffc5d71 100644 --- a/test/chunk/chunk.js +++ b/test/chunk/chunk.js @@ -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 \ No newline at end of file +module.exports = chunk \ No newline at end of file diff --git a/test/chunk/chunk.test.js b/test/chunk/chunk.test.js index a4dc0051a..348d04f49 100644 --- a/test/chunk/chunk.test.js +++ b/test/chunk/chunk.test.js @@ -2,11 +2,11 @@ const test = require('tape'); const chunk = require('./chunk.js'); test('Testing chunk', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape t.true(typeof chunk === 'function', 'chunk is a Function'); - t.deepEqual(chunk([1, 2, 3, 4, 5], 2), [[1,2],[3,4],[5]], "chunk([1, 2, 3, 4, 5], 2) returns [[1,2],[3,4],[5]] "); - t.deepEqual(chunk([]), [], 'chunk([]) returns []'); + t.deepEqual(chunk([1, 2, 3, 4, 5], 2), [[1,2],[3,4],[5]], "chunk([1, 2, 3, 4, 5], 2) returns [[1,2],[3,4],[5]] "); + t.deepEqual(chunk([]), [], 'chunk([]) returns []'); t.deepEqual(chunk(123), [], 'chunk(123) returns []'); t.deepEqual(chunk({ a: 123}), [], 'chunk({ a: 123}) returns []'); t.deepEqual(chunk('string', 2), [ 'st', 'ri', 'ng' ], 'chunk(string, 2) returns [ st, ri, ng ]'); diff --git a/test/clampNumber/clampNumber.js b/test/clampNumber/clampNumber.js index 5033a0372..ecd804f73 100644 --- a/test/clampNumber/clampNumber.js +++ b/test/clampNumber/clampNumber.js @@ -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 \ No newline at end of file +module.exports = clampNumber \ No newline at end of file diff --git a/test/clampNumber/clampNumber.test.js b/test/clampNumber/clampNumber.test.js index 6cc3b3029..0e62c5b8f 100644 --- a/test/clampNumber/clampNumber.test.js +++ b/test/clampNumber/clampNumber.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const clampNumber = require('./clampNumber.js'); test('Testing clampNumber', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof clampNumber === 'function', 'clampNumber is a Function'); - t.equal(clampNumber(2, 3, 5), 3, "Clamps num within the inclusive range specified by the boundary values a and b"); - //t.deepEqual(clampNumber(args..), 'Expected'); - //t.equal(clampNumber(args..), 'Expected'); - //t.false(clampNumber(args..), 'Expected'); - //t.throws(clampNumber(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof clampNumber === 'function', 'clampNumber is a Function'); + t.equal(clampNumber(2, 3, 5), 3, "Clamps num within the inclusive range specified by the boundary values a and b"); + //t.deepEqual(clampNumber(args..), 'Expected'); + //t.equal(clampNumber(args..), 'Expected'); + //t.false(clampNumber(args..), 'Expected'); + //t.throws(clampNumber(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/cleanObj/cleanObj.js b/test/cleanObj/cleanObj.js index 16f414bec..d3dfc14d3 100644 --- a/test/cleanObj/cleanObj.js +++ b/test/cleanObj/cleanObj.js @@ -8,4 +8,4 @@ delete obj[key]; }); return obj; }; - module.exports = cleanObj \ No newline at end of file +module.exports = cleanObj \ No newline at end of file diff --git a/test/cleanObj/cleanObj.test.js b/test/cleanObj/cleanObj.test.js index 8869354da..db490ed45 100644 --- a/test/cleanObj/cleanObj.test.js +++ b/test/cleanObj/cleanObj.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const cleanObj = require('./cleanObj.js'); test('Testing cleanObj', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof cleanObj === 'function', 'cleanObj is a Function'); - const testObj = { a: 1, b: 2, children: { a: 1, b: 2 } }; - t.deepEqual(cleanObj(testObj, ['a'], 'children'), { a: 1, children : { a: 1}}, "Removes any properties except the ones specified from a JSON object"); - //t.deepEqual(cleanObj(args..), 'Expected'); - //t.equal(cleanObj(args..), 'Expected'); - //t.false(cleanObj(args..), 'Expected'); - //t.throws(cleanObj(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof cleanObj === 'function', 'cleanObj is a Function'); + const testObj = { a: 1, b: 2, children: { a: 1, b: 2 } }; + t.deepEqual(cleanObj(testObj, ['a'], 'children'), { a: 1, children : { a: 1}}, "Removes any properties except the ones specified from a JSON object"); + //t.deepEqual(cleanObj(args..), 'Expected'); + //t.equal(cleanObj(args..), 'Expected'); + //t.false(cleanObj(args..), 'Expected'); + //t.throws(cleanObj(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/cloneRegExp/cloneRegExp.js b/test/cloneRegExp/cloneRegExp.js index 41d81e621..d0fdb3953 100644 --- a/test/cloneRegExp/cloneRegExp.js +++ b/test/cloneRegExp/cloneRegExp.js @@ -1,2 +1,2 @@ const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags); - module.exports = cloneRegExp \ No newline at end of file +module.exports = cloneRegExp \ No newline at end of file diff --git a/test/cloneRegExp/cloneRegExp.test.js b/test/cloneRegExp/cloneRegExp.test.js index 2fb7f7b82..17b2ce8c0 100644 --- a/test/cloneRegExp/cloneRegExp.test.js +++ b/test/cloneRegExp/cloneRegExp.test.js @@ -2,12 +2,14 @@ const test = require('tape'); const cloneRegExp = require('./cloneRegExp.js'); test('Testing cloneRegExp', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof cloneRegExp === 'function', 'cloneRegExp is a Function'); - //t.deepEqual(cloneRegExp(args..), 'Expected'); - //t.equal(cloneRegExp(args..), 'Expected'); - //t.false(cloneRegExp(args..), 'Expected'); - //t.throws(cloneRegExp(args..), 'Expected'); - t.end(); -}); \ No newline at end of file + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof cloneRegExp === 'function', 'cloneRegExp is a Function'); + const rgTest = /./g; + t.notEqual(cloneRegExp(rgTest), rgTest, 'Clones regular expressions properly'); + //t.deepEqual(cloneRegExp(args..), 'Expected'); + //t.equal(cloneRegExp(args..), 'Expected'); + //t.false(cloneRegExp(args..), 'Expected'); + //t.throws(cloneRegExp(args..), 'Expected'); + t.end(); +}); diff --git a/test/coalesce/coalesce.js b/test/coalesce/coalesce.js index 6147c753e..839e85f10 100644 --- a/test/coalesce/coalesce.js +++ b/test/coalesce/coalesce.js @@ -1,2 +1,2 @@ const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_)); - module.exports = coalesce \ No newline at end of file +module.exports = coalesce \ No newline at end of file diff --git a/test/coalesce/coalesce.test.js b/test/coalesce/coalesce.test.js index a1bd51e03..e32afaf95 100644 --- a/test/coalesce/coalesce.test.js +++ b/test/coalesce/coalesce.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const coalesce = require('./coalesce.js'); test('Testing coalesce', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof coalesce === 'function', 'coalesce is a Function'); - t.deepEqual(coalesce(null, undefined, '', NaN, 'Waldo'), '', "Returns the first non-null/undefined argument"); - //t.deepEqual(coalesce(args..), 'Expected'); - //t.equal(coalesce(args..), 'Expected'); - //t.false(coalesce(args..), 'Expected'); - //t.throws(coalesce(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof coalesce === 'function', 'coalesce is a Function'); + t.deepEqual(coalesce(null, undefined, '', NaN, 'Waldo'), '', "Returns the first non-null/undefined argument"); + //t.deepEqual(coalesce(args..), 'Expected'); + //t.equal(coalesce(args..), 'Expected'); + //t.false(coalesce(args..), 'Expected'); + //t.throws(coalesce(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/coalesceFactory/coalesceFactory.js b/test/coalesceFactory/coalesceFactory.js index 808d4c517..356ab50bb 100644 --- a/test/coalesceFactory/coalesceFactory.js +++ b/test/coalesceFactory/coalesceFactory.js @@ -1,2 +1,2 @@ const coalesceFactory = valid => (...args) => args.find(valid); - module.exports = coalesceFactory \ No newline at end of file +module.exports = coalesceFactory \ No newline at end of file diff --git a/test/coalesceFactory/coalesceFactory.test.js b/test/coalesceFactory/coalesceFactory.test.js index 0b2f019c9..e0651ace2 100644 --- a/test/coalesceFactory/coalesceFactory.test.js +++ b/test/coalesceFactory/coalesceFactory.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const coalesceFactory = require('./coalesceFactory.js'); test('Testing coalesceFactory', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof coalesceFactory === 'function', 'coalesceFactory is a Function'); - const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_)); - t.deepEqual(customCoalesce(undefined, null, NaN, '', 'Waldo'), 'Waldo', "Returns a customized coalesce function"); - //t.deepEqual(coalesceFactory(args..), 'Expected'); - //t.equal(coalesceFactory(args..), 'Expected'); - //t.false(coalesceFactory(args..), 'Expected'); - //t.throws(coalesceFactory(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof coalesceFactory === 'function', 'coalesceFactory is a Function'); + const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_)); + t.deepEqual(customCoalesce(undefined, null, NaN, '', 'Waldo'), 'Waldo', "Returns a customized coalesce function"); + //t.deepEqual(coalesceFactory(args..), 'Expected'); + //t.equal(coalesceFactory(args..), 'Expected'); + //t.false(coalesceFactory(args..), 'Expected'); + //t.throws(coalesceFactory(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/collatz/collatz.js b/test/collatz/collatz.js index 90f826b59..a5ea21085 100644 --- a/test/collatz/collatz.js +++ b/test/collatz/collatz.js @@ -1,2 +1,2 @@ const collatz = n => (n % 2 == 0 ? n / 2 : 3 * n + 1); - module.exports = collatz \ No newline at end of file +module.exports = collatz \ No newline at end of file diff --git a/test/collatz/collatz.test.js b/test/collatz/collatz.test.js index d713c999d..1922e40ed 100644 --- a/test/collatz/collatz.test.js +++ b/test/collatz/collatz.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const collatz = require('./collatz.js'); test('Testing collatz', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof collatz === 'function', 'collatz is a Function'); - //t.deepEqual(collatz(args..), 'Expected'); - //t.equal(collatz(args..), 'Expected'); - //t.false(collatz(args..), 'Expected'); - //t.throws(collatz(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof collatz === 'function', 'collatz is a Function'); + //t.deepEqual(collatz(args..), 'Expected'); + //t.equal(collatz(args..), 'Expected'); + //t.false(collatz(args..), 'Expected'); + //t.throws(collatz(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/collectInto/collectInto.js b/test/collectInto/collectInto.js index d8873dcec..829b8844b 100644 --- a/test/collectInto/collectInto.js +++ b/test/collectInto/collectInto.js @@ -1,2 +1,2 @@ const collectInto = fn => (...args) => fn(args); - module.exports = collectInto \ No newline at end of file +module.exports = collectInto \ No newline at end of file diff --git a/test/collectInto/collectInto.test.js b/test/collectInto/collectInto.test.js index 99407663e..a3d303e5a 100644 --- a/test/collectInto/collectInto.test.js +++ b/test/collectInto/collectInto.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const collectInto = require('./collectInto.js'); test('Testing collectInto', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof collectInto === 'function', 'collectInto is a Function'); - //t.deepEqual(collectInto(args..), 'Expected'); - //t.equal(collectInto(args..), 'Expected'); - //t.false(collectInto(args..), 'Expected'); - //t.throws(collectInto(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof collectInto === 'function', 'collectInto is a Function'); + //t.deepEqual(collectInto(args..), 'Expected'); + //t.equal(collectInto(args..), 'Expected'); + //t.false(collectInto(args..), 'Expected'); + //t.throws(collectInto(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/colorize/colorize.js b/test/colorize/colorize.js index 47c88dd49..63e7f7d29 100644 --- a/test/colorize/colorize.js +++ b/test/colorize/colorize.js @@ -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 \ No newline at end of file +module.exports = colorize \ No newline at end of file diff --git a/test/colorize/colorize.test.js b/test/colorize/colorize.test.js index a20fe2a3f..29ff32ef2 100644 --- a/test/colorize/colorize.test.js +++ b/test/colorize/colorize.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const colorize = require('./colorize.js'); test('Testing colorize', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof colorize === 'function', 'colorize is a Function'); - //t.deepEqual(colorize(args..), 'Expected'); - //t.equal(colorize(args..), 'Expected'); - //t.false(colorize(args..), 'Expected'); - //t.throws(colorize(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof colorize === 'function', 'colorize is a Function'); + //t.deepEqual(colorize(args..), 'Expected'); + //t.equal(colorize(args..), 'Expected'); + //t.false(colorize(args..), 'Expected'); + //t.throws(colorize(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/compact/compact.js b/test/compact/compact.js index da480df6b..24866fe96 100644 --- a/test/compact/compact.js +++ b/test/compact/compact.js @@ -1,2 +1,2 @@ const compact = arr => arr.filter(Boolean); - module.exports = compact \ No newline at end of file +module.exports = compact \ No newline at end of file diff --git a/test/compact/compact.test.js b/test/compact/compact.test.js index 6c03b0f5e..74de02b1b 100644 --- a/test/compact/compact.test.js +++ b/test/compact/compact.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const compact = require('./compact.js'); test('Testing compact', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof compact === 'function', 'compact is a Function'); - t.deepEqual(compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34]), [ 1, 2, 3, 'a', 's', 34 ], "Removes falsey values from an array"); - //t.deepEqual(compact(args..), 'Expected'); - //t.equal(compact(args..), 'Expected'); - //t.false(compact(args..), 'Expected'); - //t.throws(compact(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof compact === 'function', 'compact is a Function'); + t.deepEqual(compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34]), [ 1, 2, 3, 'a', 's', 34 ], "Removes falsey values from an array"); + //t.deepEqual(compact(args..), 'Expected'); + //t.equal(compact(args..), 'Expected'); + //t.false(compact(args..), 'Expected'); + //t.throws(compact(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/compose/compose.js b/test/compose/compose.js index ec5564b31..b4e352b0b 100644 --- a/test/compose/compose.js +++ b/test/compose/compose.js @@ -1,2 +1,2 @@ const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))); - module.exports = compose \ No newline at end of file +module.exports = compose \ No newline at end of file diff --git a/test/compose/compose.test.js b/test/compose/compose.test.js index 97d0304bc..87c2ea8bd 100644 --- a/test/compose/compose.test.js +++ b/test/compose/compose.test.js @@ -2,16 +2,16 @@ const test = require('tape'); const compose = require('./compose.js'); test('Testing compose', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof compose === 'function', 'compose is a Function'); - const add5 = x => x + 5; - const multiply = (x, y) => x * y; - const multiplyAndAdd5 = compose(add5, multiply); - t.equal(multiplyAndAdd5(5, 2), 15, "Performs right-to-left function composition"); - //t.deepEqual(compose(args..), 'Expected'); - //t.equal(compose(args..), 'Expected'); - //t.false(compose(args..), 'Expected'); - //t.throws(compose(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof compose === 'function', 'compose is a Function'); + const add5 = x => x + 5; + const multiply = (x, y) => x * y; + const multiplyAndAdd5 = compose(add5, multiply); + t.equal(multiplyAndAdd5(5, 2), 15, "Performs right-to-left function composition"); + //t.deepEqual(compose(args..), 'Expected'); + //t.equal(compose(args..), 'Expected'); + //t.false(compose(args..), 'Expected'); + //t.throws(compose(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/composeRight/composeRight.js b/test/composeRight/composeRight.js new file mode 100644 index 000000000..3e17a2b91 --- /dev/null +++ b/test/composeRight/composeRight.js @@ -0,0 +1,2 @@ +const composeRight = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args))); +module.exports = composeRight \ No newline at end of file diff --git a/test/composeRight/composeRight.test.js b/test/composeRight/composeRight.test.js new file mode 100644 index 000000000..c07f7e8a5 --- /dev/null +++ b/test/composeRight/composeRight.test.js @@ -0,0 +1,17 @@ +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'); + const add = (x, y) => x + y; + const square = x => x * x; + const addAndSquare = composeRight(add, square); + t.equal(addAndSquare(1, 2), 9, "Performs left-to-right function composition"); + //t.deepEqual(composeRight(args..), 'Expected'); + //t.equal(composeRight(args..), 'Expected'); + //t.false(composeRight(args..), 'Expected'); + //t.throws(composeRight(args..), 'Expected'); + t.end(); +}); diff --git a/test/copyToClipboard/copyToClipboard.js b/test/copyToClipboard/copyToClipboard.js index c1a18c196..5af7138b6 100644 --- a/test/copyToClipboard/copyToClipboard.js +++ b/test/copyToClipboard/copyToClipboard.js @@ -15,4 +15,4 @@ document.getSelection().removeAllRanges(); document.getSelection().addRange(selected); } }; - module.exports = copyToClipboard \ No newline at end of file +module.exports = copyToClipboard \ No newline at end of file diff --git a/test/copyToClipboard/copyToClipboard.test.js b/test/copyToClipboard/copyToClipboard.test.js index af7678391..83d9419da 100644 --- a/test/copyToClipboard/copyToClipboard.test.js +++ b/test/copyToClipboard/copyToClipboard.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const copyToClipboard = require('./copyToClipboard.js'); test('Testing copyToClipboard', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof copyToClipboard === 'function', 'copyToClipboard is a Function'); - //t.deepEqual(copyToClipboard(args..), 'Expected'); - //t.equal(copyToClipboard(args..), 'Expected'); - //t.false(copyToClipboard(args..), 'Expected'); - //t.throws(copyToClipboard(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof copyToClipboard === 'function', 'copyToClipboard is a Function'); + //t.deepEqual(copyToClipboard(args..), 'Expected'); + //t.equal(copyToClipboard(args..), 'Expected'); + //t.false(copyToClipboard(args..), 'Expected'); + //t.throws(copyToClipboard(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/countBy/countBy.js b/test/countBy/countBy.js index dc5aea920..fdd3f3f92 100644 --- a/test/countBy/countBy.js +++ b/test/countBy/countBy.js @@ -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 \ No newline at end of file +module.exports = countBy \ No newline at end of file diff --git a/test/countBy/countBy.test.js b/test/countBy/countBy.test.js index 24ca39f7e..ea6c3b748 100644 --- a/test/countBy/countBy.test.js +++ b/test/countBy/countBy.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const countBy = require('./countBy.js'); test('Testing countBy', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof countBy === 'function', 'countBy is a Function'); - //t.deepEqual(countBy(args..), 'Expected'); - //t.equal(countBy(args..), 'Expected'); - //t.false(countBy(args..), 'Expected'); - //t.throws(countBy(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof countBy === 'function', 'countBy is a Function'); + //t.deepEqual(countBy(args..), 'Expected'); + //t.equal(countBy(args..), 'Expected'); + //t.false(countBy(args..), 'Expected'); + //t.throws(countBy(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/countOccurrences/countOccurrences.js b/test/countOccurrences/countOccurrences.js index cb03497f6..bc76c8bc3 100644 --- a/test/countOccurrences/countOccurrences.js +++ b/test/countOccurrences/countOccurrences.js @@ -1,2 +1,2 @@ const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a + 0), 0); - module.exports = countOccurrences \ No newline at end of file +module.exports = countOccurrences \ No newline at end of file diff --git a/test/countOccurrences/countOccurrences.test.js b/test/countOccurrences/countOccurrences.test.js index 1f160ff52..1459d5ae8 100644 --- a/test/countOccurrences/countOccurrences.test.js +++ b/test/countOccurrences/countOccurrences.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const countOccurrences = require('./countOccurrences.js'); test('Testing countOccurrences', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof countOccurrences === 'function', 'countOccurrences is a Function'); - t.deepEqual(countOccurrences([1, 1, 2, 1, 2, 3], 1), 3, "Counts the occurrences of a value in an array"); - //t.deepEqual(countOccurrences(args..), 'Expected'); - //t.equal(countOccurrences(args..), 'Expected'); - //t.false(countOccurrences(args..), 'Expected'); - //t.throws(countOccurrences(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof countOccurrences === 'function', 'countOccurrences is a Function'); + t.deepEqual(countOccurrences([1, 1, 2, 1, 2, 3], 1), 3, "Counts the occurrences of a value in an array"); + //t.deepEqual(countOccurrences(args..), 'Expected'); + //t.equal(countOccurrences(args..), 'Expected'); + //t.false(countOccurrences(args..), 'Expected'); + //t.throws(countOccurrences(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/countVowels/countVowels.js b/test/countVowels/countVowels.js index 62194dc8b..cf9730c41 100644 --- a/test/countVowels/countVowels.js +++ b/test/countVowels/countVowels.js @@ -1,2 +1,2 @@ const countVowels = str => (str.match(/[aeiou]/gi) || []).length; - module.exports = countVowels \ No newline at end of file +module.exports = countVowels \ No newline at end of file diff --git a/test/countVowels/countVowels.test.js b/test/countVowels/countVowels.test.js index 2b91572e9..98a67a2b1 100644 --- a/test/countVowels/countVowels.test.js +++ b/test/countVowels/countVowels.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const countVowels = require('./countVowels.js'); test('Testing countVowels', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof countVowels === 'function', 'countVowels is a Function'); - //t.deepEqual(countVowels(args..), 'Expected'); - //t.equal(countVowels(args..), 'Expected'); - //t.false(countVowels(args..), 'Expected'); - //t.throws(countVowels(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof countVowels === 'function', 'countVowels is a Function'); + //t.deepEqual(countVowels(args..), 'Expected'); + //t.equal(countVowels(args..), 'Expected'); + //t.false(countVowels(args..), 'Expected'); + //t.throws(countVowels(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/createElement/createElement.js b/test/createElement/createElement.js index 8786e0056..a9d6062e8 100644 --- a/test/createElement/createElement.js +++ b/test/createElement/createElement.js @@ -3,4 +3,4 @@ const el = document.createElement('div'); el.innerHTML = str; return el.firstElementChild; }; - module.exports = createElement \ No newline at end of file +module.exports = createElement \ No newline at end of file diff --git a/test/createElement/createElement.test.js b/test/createElement/createElement.test.js index bda8d943e..f773ea672 100644 --- a/test/createElement/createElement.test.js +++ b/test/createElement/createElement.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const createElement = require('./createElement.js'); test('Testing createElement', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof createElement === 'function', 'createElement is a Function'); - //t.deepEqual(createElement(args..), 'Expected'); - //t.equal(createElement(args..), 'Expected'); - //t.false(createElement(args..), 'Expected'); - //t.throws(createElement(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof createElement === 'function', 'createElement is a Function'); + //t.deepEqual(createElement(args..), 'Expected'); + //t.equal(createElement(args..), 'Expected'); + //t.false(createElement(args..), 'Expected'); + //t.throws(createElement(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/createEventHub/createEventHub.js b/test/createEventHub/createEventHub.js index 6b85e5613..82a792026 100644 --- a/test/createEventHub/createEventHub.js +++ b/test/createEventHub/createEventHub.js @@ -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 \ No newline at end of file +module.exports = createEventHub \ No newline at end of file diff --git a/test/createEventHub/createEventHub.test.js b/test/createEventHub/createEventHub.test.js index 527237cf4..759c461b3 100644 --- a/test/createEventHub/createEventHub.test.js +++ b/test/createEventHub/createEventHub.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const createEventHub = require('./createEventHub.js'); test('Testing createEventHub', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof createEventHub === 'function', 'createEventHub is a Function'); - //t.deepEqual(createEventHub(args..), 'Expected'); - //t.equal(createEventHub(args..), 'Expected'); - //t.false(createEventHub(args..), 'Expected'); - //t.throws(createEventHub(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof createEventHub === 'function', 'createEventHub is a Function'); + //t.deepEqual(createEventHub(args..), 'Expected'); + //t.equal(createEventHub(args..), 'Expected'); + //t.false(createEventHub(args..), 'Expected'); + //t.throws(createEventHub(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/currentURL/currentURL.js b/test/currentURL/currentURL.js index e7f2b6885..47c9e8867 100644 --- a/test/currentURL/currentURL.js +++ b/test/currentURL/currentURL.js @@ -1,2 +1,2 @@ const currentURL = () => window.location.href; - module.exports = currentURL \ No newline at end of file +module.exports = currentURL \ No newline at end of file diff --git a/test/currentURL/currentURL.test.js b/test/currentURL/currentURL.test.js index ee9f82d9c..e7dba8ee4 100644 --- a/test/currentURL/currentURL.test.js +++ b/test/currentURL/currentURL.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const currentURL = require('./currentURL.js'); test('Testing currentURL', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof currentURL === 'function', 'currentURL is a Function'); - //t.deepEqual(currentURL(args..), 'Expected'); - //t.equal(currentURL(args..), 'Expected'); - //t.false(currentURL(args..), 'Expected'); - //t.throws(currentURL(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof currentURL === 'function', 'currentURL is a Function'); + //t.deepEqual(currentURL(args..), 'Expected'); + //t.equal(currentURL(args..), 'Expected'); + //t.false(currentURL(args..), 'Expected'); + //t.throws(currentURL(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/curry/curry.js b/test/curry/curry.js index d0109e427..ca08777f9 100644 --- a/test/curry/curry.js +++ b/test/curry/curry.js @@ -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 \ No newline at end of file +module.exports = curry \ No newline at end of file diff --git a/test/curry/curry.test.js b/test/curry/curry.test.js index a8014b100..341b11811 100644 --- a/test/curry/curry.test.js +++ b/test/curry/curry.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const curry = require('./curry.js'); test('Testing curry', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof curry === 'function', 'curry is a Function'); - t.equal(curry(Math.pow)(2)(10), 1024, "curries a Math.pow"); - t.equal(curry(Math.min, 3)(10)(50)(2), 2, "curries a Math.min"); - //t.deepEqual(curry(args..), 'Expected'); - //t.equal(curry(args..), 'Expected'); - //t.false(curry(args..), 'Expected'); - //t.throws(curry(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof curry === 'function', 'curry is a Function'); + t.equal(curry(Math.pow)(2)(10), 1024, "curries a Math.pow"); + t.equal(curry(Math.min, 3)(10)(50)(2), 2, "curries a Math.min"); + //t.deepEqual(curry(args..), 'Expected'); + //t.equal(curry(args..), 'Expected'); + //t.false(curry(args..), 'Expected'); + //t.throws(curry(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/decapitalize/decapitalize.js b/test/decapitalize/decapitalize.js index c42322649..b27279ebc 100644 --- a/test/decapitalize/decapitalize.js +++ b/test/decapitalize/decapitalize.js @@ -1,3 +1,3 @@ const decapitalize = ([first, ...rest], upperRest = false) => first.toLowerCase() + (upperRest ? rest.join('').toUpperCase() : rest.join('')); - module.exports = decapitalize \ No newline at end of file +module.exports = decapitalize \ No newline at end of file diff --git a/test/decapitalize/decapitalize.test.js b/test/decapitalize/decapitalize.test.js index 5ce0e6f5c..c18264447 100644 --- a/test/decapitalize/decapitalize.test.js +++ b/test/decapitalize/decapitalize.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const decapitalize = require('./decapitalize.js'); test('Testing decapitalize', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof decapitalize === 'function', 'decapitalize is a Function'); - //t.deepEqual(decapitalize(args..), 'Expected'); - //t.equal(decapitalize(args..), 'Expected'); - //t.false(decapitalize(args..), 'Expected'); - //t.throws(decapitalize(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof decapitalize === 'function', 'decapitalize is a Function'); + //t.deepEqual(decapitalize(args..), 'Expected'); + //t.equal(decapitalize(args..), 'Expected'); + //t.false(decapitalize(args..), 'Expected'); + //t.throws(decapitalize(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/deepClone/deepClone.js b/test/deepClone/deepClone.js new file mode 100644 index 000000000..fdb424f30 --- /dev/null +++ b/test/deepClone/deepClone.js @@ -0,0 +1,8 @@ +const deepClone = obj => { +let clone = Object.assign({}, obj); +Object.keys(clone).forEach( +key => (clone[key] = typeof obj[key] === 'object' ? deepClone(obj[key]) : obj[key]) +); +return clone; +}; +module.exports = deepClone \ No newline at end of file diff --git a/test/deepClone/deepClone.test.js b/test/deepClone/deepClone.test.js new file mode 100644 index 000000000..03c936c46 --- /dev/null +++ b/test/deepClone/deepClone.test.js @@ -0,0 +1,17 @@ +const test = require('tape'); +const deepClone = require('./deepClone.js'); + +test('Testing deepClone', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof deepClone === 'function', 'deepClone is a Function'); + const a = { foo: 'bar', obj: { a: 1, b: 2 } }; + const b = deepClone(a); + t.notEqual(a, b, 'Shallow cloning works'); + t.notEqual(a.obj, b.obj, 'Deep cloning works'); + //t.deepEqual(deepClone(args..), 'Expected'); + //t.equal(deepClone(args..), 'Expected'); + //t.false(deepClone(args..), 'Expected'); + //t.throws(deepClone(args..), 'Expected'); + t.end(); +}); diff --git a/test/deepFlatten/deepFlatten.js b/test/deepFlatten/deepFlatten.js index f6e7cc6d6..7b6736558 100644 --- a/test/deepFlatten/deepFlatten.js +++ b/test/deepFlatten/deepFlatten.js @@ -1,2 +1,2 @@ const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v))); - module.exports = deepFlatten \ No newline at end of file +module.exports = deepFlatten \ No newline at end of file diff --git a/test/deepFlatten/deepFlatten.test.js b/test/deepFlatten/deepFlatten.test.js index 78db29885..d6225da28 100644 --- a/test/deepFlatten/deepFlatten.test.js +++ b/test/deepFlatten/deepFlatten.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const deepFlatten = require('./deepFlatten.js'); test('Testing deepFlatten', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof deepFlatten === 'function', 'deepFlatten is a Function'); - t.deepEqual(deepFlatten([1, [2], [[3], 4], 5]), [1, 2, 3, 4, 5], "Deep flattens an array"); - //t.deepEqual(deepFlatten(args..), 'Expected'); - //t.equal(deepFlatten(args..), 'Expected'); - //t.false(deepFlatten(args..), 'Expected'); - //t.throws(deepFlatten(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof deepFlatten === 'function', 'deepFlatten is a Function'); + t.deepEqual(deepFlatten([1, [2], [[3], 4], 5]), [1, 2, 3, 4, 5], "Deep flattens an array"); + //t.deepEqual(deepFlatten(args..), 'Expected'); + //t.equal(deepFlatten(args..), 'Expected'); + //t.false(deepFlatten(args..), 'Expected'); + //t.throws(deepFlatten(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/defaults/defaults.js b/test/defaults/defaults.js new file mode 100644 index 000000000..bb66f6cc1 --- /dev/null +++ b/test/defaults/defaults.js @@ -0,0 +1,2 @@ +const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj); +module.exports = defaults \ No newline at end of file diff --git a/test/defaults/defaults.test.js b/test/defaults/defaults.test.js new file mode 100644 index 000000000..ab1afa29e --- /dev/null +++ b/test/defaults/defaults.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const defaults = require('./defaults.js'); + +test('Testing defaults', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof defaults === 'function', 'defaults is a Function'); + //t.deepEqual(defaults(args..), 'Expected'); + //t.equal(defaults(args..), 'Expected'); + //t.false(defaults(args..), 'Expected'); + //t.throws(defaults(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/defer/defer.js b/test/defer/defer.js index f5562f3c7..fd555a267 100644 --- a/test/defer/defer.js +++ b/test/defer/defer.js @@ -1,2 +1,2 @@ const defer = (fn, ...args) => setTimeout(fn, 1, ...args); - module.exports = defer \ No newline at end of file +module.exports = defer \ No newline at end of file diff --git a/test/defer/defer.test.js b/test/defer/defer.test.js index b019474ba..faa5731c9 100644 --- a/test/defer/defer.test.js +++ b/test/defer/defer.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const defer = require('./defer.js'); test('Testing defer', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof defer === 'function', 'defer is a Function'); - //t.deepEqual(defer(args..), 'Expected'); - //t.equal(defer(args..), 'Expected'); - //t.false(defer(args..), 'Expected'); - //t.throws(defer(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof defer === 'function', 'defer is a Function'); + //t.deepEqual(defer(args..), 'Expected'); + //t.equal(defer(args..), 'Expected'); + //t.false(defer(args..), 'Expected'); + //t.throws(defer(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/delay/delay.js b/test/delay/delay.js new file mode 100644 index 000000000..2c5f8ef20 --- /dev/null +++ b/test/delay/delay.js @@ -0,0 +1,2 @@ +const delay = (fn, wait, ...args) => setTimeout(fn, wait, ...args); +module.exports = delay \ No newline at end of file diff --git a/test/delay/delay.test.js b/test/delay/delay.test.js new file mode 100644 index 000000000..544f8632d --- /dev/null +++ b/test/delay/delay.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const delay = require('./delay.js'); + +test('Testing delay', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof delay === 'function', 'delay is a Function'); + //t.deepEqual(delay(args..), 'Expected'); + //t.equal(delay(args..), 'Expected'); + //t.false(delay(args..), 'Expected'); + //t.throws(delay(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/detectDeviceType/detectDeviceType.js b/test/detectDeviceType/detectDeviceType.js index d66cb7429..e2d834fd0 100644 --- a/test/detectDeviceType/detectDeviceType.js +++ b/test/detectDeviceType/detectDeviceType.js @@ -2,4 +2,4 @@ const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? 'Mobile' : 'Desktop'; - module.exports = detectDeviceType \ No newline at end of file +module.exports = detectDeviceType \ No newline at end of file diff --git a/test/detectDeviceType/detectDeviceType.test.js b/test/detectDeviceType/detectDeviceType.test.js index 8795d1650..365388681 100644 --- a/test/detectDeviceType/detectDeviceType.test.js +++ b/test/detectDeviceType/detectDeviceType.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const detectDeviceType = require('./detectDeviceType.js'); test('Testing detectDeviceType', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof detectDeviceType === 'function', 'detectDeviceType is a Function'); - //t.deepEqual(detectDeviceType(args..), 'Expected'); - //t.equal(detectDeviceType(args..), 'Expected'); - //t.false(detectDeviceType(args..), 'Expected'); - //t.throws(detectDeviceType(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof detectDeviceType === 'function', 'detectDeviceType is a Function'); + //t.deepEqual(detectDeviceType(args..), 'Expected'); + //t.equal(detectDeviceType(args..), 'Expected'); + //t.false(detectDeviceType(args..), 'Expected'); + //t.throws(detectDeviceType(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/difference/difference.js b/test/difference/difference.js index 48fa645c5..3a2642b5b 100644 --- a/test/difference/difference.js +++ b/test/difference/difference.js @@ -2,4 +2,4 @@ const difference = (a, b) => { const s = new Set(b); return a.filter(x => !s.has(x)); }; - module.exports = difference \ No newline at end of file +module.exports = difference \ No newline at end of file diff --git a/test/difference/difference.test.js b/test/difference/difference.test.js index 4adeb6577..17a5b7ba2 100644 --- a/test/difference/difference.test.js +++ b/test/difference/difference.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const difference = require('./difference.js'); test('Testing difference', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof difference === 'function', 'difference is a Function'); - t.deepEqual(difference([1, 2, 3], [1, 2, 4]), [3], "Returns the difference between two arrays"); - //t.deepEqual(difference(args..), 'Expected'); - //t.equal(difference(args..), 'Expected'); - //t.false(difference(args..), 'Expected'); - //t.throws(difference(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof difference === 'function', 'difference is a Function'); + t.deepEqual(difference([1, 2, 3], [1, 2, 4]), [3], "Returns the difference between two arrays"); + //t.deepEqual(difference(args..), 'Expected'); + //t.equal(difference(args..), 'Expected'); + //t.false(difference(args..), 'Expected'); + //t.throws(difference(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/differenceBy/differenceBy.js b/test/differenceBy/differenceBy.js new file mode 100644 index 000000000..84e5548bb --- /dev/null +++ b/test/differenceBy/differenceBy.js @@ -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 \ No newline at end of file diff --git a/test/differenceBy/differenceBy.test.js b/test/differenceBy/differenceBy.test.js new file mode 100644 index 000000000..377de9614 --- /dev/null +++ b/test/differenceBy/differenceBy.test.js @@ -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(); +}); \ No newline at end of file diff --git a/test/differenceWith/differenceWith.js b/test/differenceWith/differenceWith.js index 2d173c9c3..83db305b1 100644 --- a/test/differenceWith/differenceWith.js +++ b/test/differenceWith/differenceWith.js @@ -1,2 +1,2 @@ const differenceWith = (arr, val, comp) => arr.filter(a => val.findIndex(b => comp(a, b)) === -1); - module.exports = differenceWith \ No newline at end of file +module.exports = differenceWith \ No newline at end of file diff --git a/test/differenceWith/differenceWith.test.js b/test/differenceWith/differenceWith.test.js index edeae5bf4..b3dd65cd5 100644 --- a/test/differenceWith/differenceWith.test.js +++ b/test/differenceWith/differenceWith.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const differenceWith = require('./differenceWith.js'); test('Testing differenceWith', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof differenceWith === 'function', 'differenceWith is a Function'); - t.deepEqual(differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Math.round(b)), [1, 1.2], "Filters out all values from an array"); - //t.deepEqual(differenceWith(args..), 'Expected'); - //t.equal(differenceWith(args..), 'Expected'); - //t.false(differenceWith(args..), 'Expected'); - //t.throws(differenceWith(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof differenceWith === 'function', 'differenceWith is a Function'); + t.deepEqual(differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Math.round(b)), [1, 1.2], "Filters out all values from an array"); + //t.deepEqual(differenceWith(args..), 'Expected'); + //t.equal(differenceWith(args..), 'Expected'); + //t.false(differenceWith(args..), 'Expected'); + //t.throws(differenceWith(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/digitize/digitize.js b/test/digitize/digitize.js index d34c01e6a..b6324fe65 100644 --- a/test/digitize/digitize.js +++ b/test/digitize/digitize.js @@ -1,2 +1,2 @@ const digitize = n => [...`${n}`].map(i => parseInt(i)); - module.exports = digitize \ No newline at end of file +module.exports = digitize \ No newline at end of file diff --git a/test/digitize/digitize.test.js b/test/digitize/digitize.test.js index 93a67e7eb..2fb81a471 100644 --- a/test/digitize/digitize.test.js +++ b/test/digitize/digitize.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const digitize = require('./digitize.js'); test('Testing digitize', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof digitize === 'function', 'digitize is a Function'); - t.deepEqual(digitize(123), [1, 2, 3], "Converts a number to an array of digits"); - //t.deepEqual(digitize(args..), 'Expected'); - //t.equal(digitize(args..), 'Expected'); - //t.false(digitize(args..), 'Expected'); - //t.throws(digitize(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof digitize === 'function', 'digitize is a Function'); + t.deepEqual(digitize(123), [1, 2, 3], "Converts a number to an array of digits"); + //t.deepEqual(digitize(args..), 'Expected'); + //t.equal(digitize(args..), 'Expected'); + //t.false(digitize(args..), 'Expected'); + //t.throws(digitize(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/distance/distance.js b/test/distance/distance.js index 426517fd3..fdcbc4f15 100644 --- a/test/distance/distance.js +++ b/test/distance/distance.js @@ -1,2 +1,2 @@ const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0); - module.exports = distance \ No newline at end of file +module.exports = distance \ No newline at end of file diff --git a/test/distance/distance.test.js b/test/distance/distance.test.js index ace1084cb..e74474e75 100644 --- a/test/distance/distance.test.js +++ b/test/distance/distance.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const distance = require('./distance.js'); test('Testing distance', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof distance === 'function', 'distance is a Function'); - //t.deepEqual(distance(args..), 'Expected'); - //t.equal(distance(args..), 'Expected'); - //t.false(distance(args..), 'Expected'); - //t.throws(distance(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof distance === 'function', 'distance is a Function'); + //t.deepEqual(distance(args..), 'Expected'); + //t.equal(distance(args..), 'Expected'); + //t.false(distance(args..), 'Expected'); + //t.throws(distance(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/dropElements/dropElements.js b/test/dropElements/dropElements.js index 6484de16d..bb87783f9 100644 --- a/test/dropElements/dropElements.js +++ b/test/dropElements/dropElements.js @@ -2,4 +2,4 @@ const dropElements = (arr, func) => { while (arr.length > 0 && !func(arr[0])) arr = arr.slice(1); return arr; }; - module.exports = dropElements \ No newline at end of file +module.exports = dropElements \ No newline at end of file diff --git a/test/dropElements/dropElements.test.js b/test/dropElements/dropElements.test.js index 95c551602..b92ecd37d 100644 --- a/test/dropElements/dropElements.test.js +++ b/test/dropElements/dropElements.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const dropElements = require('./dropElements.js'); test('Testing dropElements', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof dropElements === 'function', 'dropElements is a Function'); - t.deepEqual(dropElements([1, 2, 3, 4], n => n >= 3), [3,4], "Removes elements in an array until the passed function returns true"); - //t.deepEqual(dropElements(args..), 'Expected'); - //t.equal(dropElements(args..), 'Expected'); - //t.false(dropElements(args..), 'Expected'); - //t.throws(dropElements(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof dropElements === 'function', 'dropElements is a Function'); + t.deepEqual(dropElements([1, 2, 3, 4], n => n >= 3), [3,4], "Removes elements in an array until the passed function returns true"); + //t.deepEqual(dropElements(args..), 'Expected'); + //t.equal(dropElements(args..), 'Expected'); + //t.false(dropElements(args..), 'Expected'); + //t.throws(dropElements(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/dropRight/dropRight.js b/test/dropRight/dropRight.js index 8e89e36b4..6e5e6725b 100644 --- a/test/dropRight/dropRight.js +++ b/test/dropRight/dropRight.js @@ -1,2 +1,2 @@ const dropRight = (arr, n = 1) => arr.slice(0, -n); - module.exports = dropRight \ No newline at end of file +module.exports = dropRight \ No newline at end of file diff --git a/test/dropRight/dropRight.test.js b/test/dropRight/dropRight.test.js index 8a347b736..b224b0a47 100644 --- a/test/dropRight/dropRight.test.js +++ b/test/dropRight/dropRight.test.js @@ -2,15 +2,15 @@ const test = require('tape'); const dropRight = require('./dropRight.js'); test('Testing dropRight', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof dropRight === 'function', 'dropRight is a Function'); - t.deepEqual(dropRight([1, 2, 3]), [1,2], "Returns a new array with n elements removed from the right"); - t.deepEqual(dropRight([1, 2, 3], 2), [1], "Returns a new array with n elements removed from the right"); - t.deepEqual(dropRight([1, 2, 3], 42), [], "Returns a new array with n elements removed from the right"); - //t.deepEqual(dropRight(args..), 'Expected'); - //t.equal(dropRight(args..), 'Expected'); - //t.false(dropRight(args..), 'Expected'); - //t.throws(dropRight(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof dropRight === 'function', 'dropRight is a Function'); + t.deepEqual(dropRight([1, 2, 3]), [1,2], "Returns a new array with n elements removed from the right"); + t.deepEqual(dropRight([1, 2, 3], 2), [1], "Returns a new array with n elements removed from the right"); + t.deepEqual(dropRight([1, 2, 3], 42), [], "Returns a new array with n elements removed from the right"); + //t.deepEqual(dropRight(args..), 'Expected'); + //t.equal(dropRight(args..), 'Expected'); + //t.false(dropRight(args..), 'Expected'); + //t.throws(dropRight(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/elementIsVisibleInViewport/elementIsVisibleInViewport.js b/test/elementIsVisibleInViewport/elementIsVisibleInViewport.js index 1925c72cd..e8033fcfa 100644 --- a/test/elementIsVisibleInViewport/elementIsVisibleInViewport.js +++ b/test/elementIsVisibleInViewport/elementIsVisibleInViewport.js @@ -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 \ No newline at end of file +module.exports = elementIsVisibleInViewport \ No newline at end of file diff --git a/test/elementIsVisibleInViewport/elementIsVisibleInViewport.test.js b/test/elementIsVisibleInViewport/elementIsVisibleInViewport.test.js index 6fd276aef..2dd349424 100644 --- a/test/elementIsVisibleInViewport/elementIsVisibleInViewport.test.js +++ b/test/elementIsVisibleInViewport/elementIsVisibleInViewport.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const elementIsVisibleInViewport = require('./elementIsVisibleInViewport.js'); test('Testing elementIsVisibleInViewport', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof elementIsVisibleInViewport === 'function', 'elementIsVisibleInViewport is a Function'); - //t.deepEqual(elementIsVisibleInViewport(args..), 'Expected'); - //t.equal(elementIsVisibleInViewport(args..), 'Expected'); - //t.false(elementIsVisibleInViewport(args..), 'Expected'); - //t.throws(elementIsVisibleInViewport(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof elementIsVisibleInViewport === 'function', 'elementIsVisibleInViewport is a Function'); + //t.deepEqual(elementIsVisibleInViewport(args..), 'Expected'); + //t.equal(elementIsVisibleInViewport(args..), 'Expected'); + //t.false(elementIsVisibleInViewport(args..), 'Expected'); + //t.throws(elementIsVisibleInViewport(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/elo/elo.js b/test/elo/elo.js index 812ee1af1..19952b6b2 100644 --- a/test/elo/elo.js +++ b/test/elo/elo.js @@ -16,4 +16,4 @@ j++; } return ratings; }; - module.exports = elo \ No newline at end of file +module.exports = elo \ No newline at end of file diff --git a/test/elo/elo.test.js b/test/elo/elo.test.js index b425f7fb1..c7f757a8e 100644 --- a/test/elo/elo.test.js +++ b/test/elo/elo.test.js @@ -2,15 +2,15 @@ const test = require('tape'); const elo = require('./elo.js'); test('Testing elo', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof elo === 'function', 'elo is a Function'); - t.deepEqual(elo([1200, 1200]), [1216, 1184], "Standard 1v1s"); - t.deepEqual(elo([1200, 1200], 64), [1232, 1168]), "Standard 1v1s"; - t.deepEqual(elo([1200, 1200, 1200, 1200]).map(Math.round), [1246, 1215, 1185, 1154], "4 player FFA, all same rank"); - //t.deepEqual(elo(args..), 'Expected'); - //t.equal(elo(args..), 'Expected'); - //t.false(elo(args..), 'Expected'); - //t.throws(elo(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof elo === 'function', 'elo is a Function'); + t.deepEqual(elo([1200, 1200]), [1216, 1184], "Standard 1v1s"); + t.deepEqual(elo([1200, 1200], 64), [1232, 1168]), "Standard 1v1s"; + t.deepEqual(elo([1200, 1200, 1200, 1200]).map(Math.round), [1246, 1215, 1185, 1154], "4 player FFA, all same rank"); + //t.deepEqual(elo(args..), 'Expected'); + //t.equal(elo(args..), 'Expected'); + //t.false(elo(args..), 'Expected'); + //t.throws(elo(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/equals/equals.js b/test/equals/equals.js index f418aa5cd..d9959f799 100644 --- a/test/equals/equals.js +++ b/test/equals/equals.js @@ -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 \ No newline at end of file +module.exports = equals \ No newline at end of file diff --git a/test/equals/equals.test.js b/test/equals/equals.test.js index eaa62a6ba..3c4caf3aa 100644 --- a/test/equals/equals.test.js +++ b/test/equals/equals.test.js @@ -2,17 +2,17 @@ const test = require('tape'); const equals = require('./equals.js'); test('Testing equals', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof equals === 'function', 'equals is a Function'); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof equals === 'function', 'equals is a Function'); t.true(equals({ a: [2, {e: 3}], b: [4], c: 'foo' }, { a: [2, {e: 3}], b: [4], c: 'foo' }), "{ a: [2, {e: 3}], b: [4], c: 'foo' } is equal to { a: [2, {e: 3}], b: [4], c: 'foo' }"); t.true(equals([1, 2, 3], [1, 2, 3]), '[1,2,3] is equal to [1,2,3]'); t.false(equals({ a: [2, 3], b: [4] }, { a: [2, 3], b: [6] }), '{ a: [2, 3], b: [4] } is not equal to { a: [2, 3], b: [6] }'); t.false(equals([1, 2, 3], [1, 2, 4]), '[1,2,3] is not equal to [1,2,4]'); t.true(equals([1, 2, 3], { 0: 1, 1: 2, 2: 3 }), '[1, 2, 3] should be equal to { 0: 1, 1: 2, 2: 3 }) - type is different, but their enumerable properties match.') - //t.deepEqual(equals(args..), 'Expected'); - //t.equal(equals(args..), 'Expected'); - //t.false(equals(args..), 'Expected'); - //t.throws(equals(args..), 'Expected'); - t.end(); + //t.deepEqual(equals(args..), 'Expected'); + //t.equal(equals(args..), 'Expected'); + //t.false(equals(args..), 'Expected'); + //t.throws(equals(args..), 'Expected'); + t.end(); }); diff --git a/test/escapeHTML/escapeHTML.js b/test/escapeHTML/escapeHTML.js index 94cb8e7fe..f1d9c874c 100644 --- a/test/escapeHTML/escapeHTML.js +++ b/test/escapeHTML/escapeHTML.js @@ -10,4 +10,4 @@ tag => '"': '"' }[tag] || tag) ); - module.exports = escapeHTML \ No newline at end of file +module.exports = escapeHTML \ No newline at end of file diff --git a/test/escapeHTML/escapeHTML.test.js b/test/escapeHTML/escapeHTML.test.js index fd116668e..642cbfd5b 100644 --- a/test/escapeHTML/escapeHTML.test.js +++ b/test/escapeHTML/escapeHTML.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const escapeHTML = require('./escapeHTML.js'); test('Testing escapeHTML', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof escapeHTML === 'function', 'escapeHTML is a Function'); - t.equal(escapeHTML('Me & you'), '<a href="#">Me & you</a>', "Escapes a string for use in HTML"); - //t.deepEqual(escapeHTML(args..), 'Expected'); - //t.equal(escapeHTML(args..), 'Expected'); - //t.false(escapeHTML(args..), 'Expected'); - //t.throws(escapeHTML(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof escapeHTML === 'function', 'escapeHTML is a Function'); + t.equal(escapeHTML('Me & you'), '<a href="#">Me & you</a>', "Escapes a string for use in HTML"); + //t.deepEqual(escapeHTML(args..), 'Expected'); + //t.equal(escapeHTML(args..), 'Expected'); + //t.false(escapeHTML(args..), 'Expected'); + //t.throws(escapeHTML(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/escapeRegExp/escapeRegExp.js b/test/escapeRegExp/escapeRegExp.js index 9164cc532..cfd2d03bf 100644 --- a/test/escapeRegExp/escapeRegExp.js +++ b/test/escapeRegExp/escapeRegExp.js @@ -1,2 +1,2 @@ const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); - module.exports = escapeRegExp \ No newline at end of file +module.exports = escapeRegExp \ No newline at end of file diff --git a/test/escapeRegExp/escapeRegExp.test.js b/test/escapeRegExp/escapeRegExp.test.js index 507b53eb8..9ecb9497a 100644 --- a/test/escapeRegExp/escapeRegExp.test.js +++ b/test/escapeRegExp/escapeRegExp.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const escapeRegExp = require('./escapeRegExp.js'); test('Testing escapeRegExp', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof escapeRegExp === 'function', 'escapeRegExp is a Function'); - t.equal(escapeRegExp('(test)'), '\\(test\\)', "Escapes a string to use in a regular expression"); - //t.deepEqual(escapeRegExp(args..), 'Expected'); - //t.equal(escapeRegExp(args..), 'Expected'); - //t.false(escapeRegExp(args..), 'Expected'); - //t.throws(escapeRegExp(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof escapeRegExp === 'function', 'escapeRegExp is a Function'); + t.equal(escapeRegExp('(test)'), '\\(test\\)', "Escapes a string to use in a regular expression"); + //t.deepEqual(escapeRegExp(args..), 'Expected'); + //t.equal(escapeRegExp(args..), 'Expected'); + //t.false(escapeRegExp(args..), 'Expected'); + //t.throws(escapeRegExp(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/everyNth/everyNth.js b/test/everyNth/everyNth.js index 723c4f5ca..12285c8f0 100644 --- a/test/everyNth/everyNth.js +++ b/test/everyNth/everyNth.js @@ -1,2 +1,2 @@ const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1); - module.exports = everyNth \ No newline at end of file +module.exports = everyNth \ No newline at end of file diff --git a/test/everyNth/everyNth.test.js b/test/everyNth/everyNth.test.js index 06f157c6a..53c3851ef 100644 --- a/test/everyNth/everyNth.test.js +++ b/test/everyNth/everyNth.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const everyNth = require('./everyNth.js'); test('Testing everyNth', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof everyNth === 'function', 'everyNth is a Function'); - t.deepEqual(everyNth([1, 2, 3, 4, 5, 6], 2), [ 2, 4, 6 ], "Returns every nth element in an array"); - //t.deepEqual(everyNth(args..), 'Expected'); - //t.equal(everyNth(args..), 'Expected'); - //t.false(everyNth(args..), 'Expected'); - //t.throws(everyNth(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof everyNth === 'function', 'everyNth is a Function'); + t.deepEqual(everyNth([1, 2, 3, 4, 5, 6], 2), [ 2, 4, 6 ], "Returns every nth element in an array"); + //t.deepEqual(everyNth(args..), 'Expected'); + //t.equal(everyNth(args..), 'Expected'); + //t.false(everyNth(args..), 'Expected'); + //t.throws(everyNth(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/extendHex/extendHex.js b/test/extendHex/extendHex.js index 6e1b6d535..fe39c39fa 100644 --- a/test/extendHex/extendHex.js +++ b/test/extendHex/extendHex.js @@ -5,4 +5,4 @@ shortHex .split('') .map(x => x + x) .join(''); - module.exports = extendHex \ No newline at end of file +module.exports = extendHex \ No newline at end of file diff --git a/test/extendHex/extendHex.test.js b/test/extendHex/extendHex.test.js index c69e8cc84..c9fd57973 100644 --- a/test/extendHex/extendHex.test.js +++ b/test/extendHex/extendHex.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const extendHex = require('./extendHex.js'); test('Testing extendHex', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof extendHex === 'function', 'extendHex is a Function'); - t.equal(extendHex('#03f'), '#0033ff', "Extends a 3-digit color code to a 6-digit color code"); - t.equal(extendHex('05a'), '#0055aa', "Extends a 3-digit color code to a 6-digit color code"); - //t.deepEqual(extendHex(args..), 'Expected'); - //t.equal(extendHex(args..), 'Expected'); - //t.false(extendHex(args..), 'Expected'); - //t.throws(extendHex(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof extendHex === 'function', 'extendHex is a Function'); + t.equal(extendHex('#03f'), '#0033ff', "Extends a 3-digit color code to a 6-digit color code"); + t.equal(extendHex('05a'), '#0055aa', "Extends a 3-digit color code to a 6-digit color code"); + //t.deepEqual(extendHex(args..), 'Expected'); + //t.equal(extendHex(args..), 'Expected'); + //t.false(extendHex(args..), 'Expected'); + //t.throws(extendHex(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/factorial/factorial.js b/test/factorial/factorial.js index 928826dea..b09e3ab26 100644 --- a/test/factorial/factorial.js +++ b/test/factorial/factorial.js @@ -4,4 +4,4 @@ n < 0 throw new TypeError('Negative numbers are not allowed!'); })() : n <= 1 ? 1 : n * factorial(n - 1); - module.exports = factorial \ No newline at end of file +module.exports = factorial \ No newline at end of file diff --git a/test/factorial/factorial.test.js b/test/factorial/factorial.test.js index 6eb4467ff..d8694b446 100644 --- a/test/factorial/factorial.test.js +++ b/test/factorial/factorial.test.js @@ -2,17 +2,17 @@ const test = require('tape'); const factorial = require('./factorial.js'); test('Testing factorial', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof factorial === 'function', 'factorial is a Function'); - t.equal(factorial(6), 720, "Calculates the factorial of 720"); - t.equal(factorial(0), 1, "Calculates the factorial of 0"); - t.equal(factorial(1), 1, "Calculates the factorial of 1"); - t.equal(factorial(4), 24, "Calculates the factorial of 4"); - t.equal(factorial(10), 3628800, "Calculates the factorial of 10"); - //t.deepEqual(factorial(args..), 'Expected'); - //t.equal(factorial(args..), 'Expected'); - //t.false(factorial(args..), 'Expected'); - //t.throws(factorial(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof factorial === 'function', 'factorial is a Function'); + t.equal(factorial(6), 720, "Calculates the factorial of 720"); + t.equal(factorial(0), 1, "Calculates the factorial of 0"); + t.equal(factorial(1), 1, "Calculates the factorial of 1"); + t.equal(factorial(4), 24, "Calculates the factorial of 4"); + t.equal(factorial(10), 3628800, "Calculates the factorial of 10"); + //t.deepEqual(factorial(args..), 'Expected'); + //t.equal(factorial(args..), 'Expected'); + //t.false(factorial(args..), 'Expected'); + //t.throws(factorial(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/factors/factors.js b/test/factors/factors.js index b34e1ded4..d0d789e83 100644 --- a/test/factors/factors.js +++ b/test/factors/factors.js @@ -17,4 +17,4 @@ return acc; }, []); return primes ? array.filter(isPrime) : array; }; - module.exports = factors \ No newline at end of file +module.exports = factors \ No newline at end of file diff --git a/test/factors/factors.test.js b/test/factors/factors.test.js index b2058c3e1..cd9d3a0c9 100644 --- a/test/factors/factors.test.js +++ b/test/factors/factors.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const factors = require('./factors.js'); test('Testing factors', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof factors === 'function', 'factors is a Function'); - //t.deepEqual(factors(args..), 'Expected'); - //t.equal(factors(args..), 'Expected'); - //t.false(factors(args..), 'Expected'); - //t.throws(factors(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof factors === 'function', 'factors is a Function'); + //t.deepEqual(factors(args..), 'Expected'); + //t.equal(factors(args..), 'Expected'); + //t.false(factors(args..), 'Expected'); + //t.throws(factors(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/fibonacci/fibonacci.js b/test/fibonacci/fibonacci.js index c6dbaf313..2fe873dc3 100644 --- a/test/fibonacci/fibonacci.js +++ b/test/fibonacci/fibonacci.js @@ -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 \ No newline at end of file +module.exports = fibonacci \ No newline at end of file diff --git a/test/fibonacci/fibonacci.test.js b/test/fibonacci/fibonacci.test.js index d15065425..75951a4de 100644 --- a/test/fibonacci/fibonacci.test.js +++ b/test/fibonacci/fibonacci.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const fibonacci = require('./fibonacci.js'); test('Testing fibonacci', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof fibonacci === 'function', 'fibonacci is a Function'); - t.deepEqual(fibonacci(6), [0, 1, 1, 2, 3, 5], "Generates an array, containing the Fibonacci sequence"); - //t.deepEqual(fibonacci(args..), 'Expected'); - //t.equal(fibonacci(args..), 'Expected'); - //t.false(fibonacci(args..), 'Expected'); - //t.throws(fibonacci(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof fibonacci === 'function', 'fibonacci is a Function'); + t.deepEqual(fibonacci(6), [0, 1, 1, 2, 3, 5], "Generates an array, containing the Fibonacci sequence"); + //t.deepEqual(fibonacci(args..), 'Expected'); + //t.equal(fibonacci(args..), 'Expected'); + //t.false(fibonacci(args..), 'Expected'); + //t.throws(fibonacci(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/fibonacciCountUntilNum/fibonacciCountUntilNum.js b/test/fibonacciCountUntilNum/fibonacciCountUntilNum.js index a23fab23b..7746208c2 100644 --- a/test/fibonacciCountUntilNum/fibonacciCountUntilNum.js +++ b/test/fibonacciCountUntilNum/fibonacciCountUntilNum.js @@ -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 \ No newline at end of file +module.exports = fibonacciCountUntilNum \ No newline at end of file diff --git a/test/fibonacciCountUntilNum/fibonacciCountUntilNum.test.js b/test/fibonacciCountUntilNum/fibonacciCountUntilNum.test.js index b8aa2498d..6d14331d3 100644 --- a/test/fibonacciCountUntilNum/fibonacciCountUntilNum.test.js +++ b/test/fibonacciCountUntilNum/fibonacciCountUntilNum.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const fibonacciCountUntilNum = require('./fibonacciCountUntilNum.js'); test('Testing fibonacciCountUntilNum', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof fibonacciCountUntilNum === 'function', 'fibonacciCountUntilNum is a Function'); - //t.deepEqual(fibonacciCountUntilNum(args..), 'Expected'); - //t.equal(fibonacciCountUntilNum(args..), 'Expected'); - //t.false(fibonacciCountUntilNum(args..), 'Expected'); - //t.throws(fibonacciCountUntilNum(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof fibonacciCountUntilNum === 'function', 'fibonacciCountUntilNum is a Function'); + //t.deepEqual(fibonacciCountUntilNum(args..), 'Expected'); + //t.equal(fibonacciCountUntilNum(args..), 'Expected'); + //t.false(fibonacciCountUntilNum(args..), 'Expected'); + //t.throws(fibonacciCountUntilNum(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/fibonacciUntilNum/fibonacciUntilNum.js b/test/fibonacciUntilNum/fibonacciUntilNum.js index 9f5a4ac32..649bd6e25 100644 --- a/test/fibonacciUntilNum/fibonacciUntilNum.js +++ b/test/fibonacciUntilNum/fibonacciUntilNum.js @@ -5,4 +5,4 @@ return Array.from({ length: n }).reduce( [] ); }; - module.exports = fibonacciUntilNum \ No newline at end of file +module.exports = fibonacciUntilNum \ No newline at end of file diff --git a/test/fibonacciUntilNum/fibonacciUntilNum.test.js b/test/fibonacciUntilNum/fibonacciUntilNum.test.js index 603df0935..a023c376c 100644 --- a/test/fibonacciUntilNum/fibonacciUntilNum.test.js +++ b/test/fibonacciUntilNum/fibonacciUntilNum.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const fibonacciUntilNum = require('./fibonacciUntilNum.js'); test('Testing fibonacciUntilNum', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof fibonacciUntilNum === 'function', 'fibonacciUntilNum is a Function'); - //t.deepEqual(fibonacciUntilNum(args..), 'Expected'); - //t.equal(fibonacciUntilNum(args..), 'Expected'); - //t.false(fibonacciUntilNum(args..), 'Expected'); - //t.throws(fibonacciUntilNum(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof fibonacciUntilNum === 'function', 'fibonacciUntilNum is a Function'); + //t.deepEqual(fibonacciUntilNum(args..), 'Expected'); + //t.equal(fibonacciUntilNum(args..), 'Expected'); + //t.false(fibonacciUntilNum(args..), 'Expected'); + //t.throws(fibonacciUntilNum(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/filterNonUnique/filterNonUnique.js b/test/filterNonUnique/filterNonUnique.js index 712cf074e..30a039b67 100644 --- a/test/filterNonUnique/filterNonUnique.js +++ b/test/filterNonUnique/filterNonUnique.js @@ -1,2 +1,2 @@ const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i)); - module.exports = filterNonUnique \ No newline at end of file +module.exports = filterNonUnique \ No newline at end of file diff --git a/test/filterNonUnique/filterNonUnique.test.js b/test/filterNonUnique/filterNonUnique.test.js index f7b06efaa..9fd18bf41 100644 --- a/test/filterNonUnique/filterNonUnique.test.js +++ b/test/filterNonUnique/filterNonUnique.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const filterNonUnique = require('./filterNonUnique.js'); test('Testing filterNonUnique', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof filterNonUnique === 'function', 'filterNonUnique is a Function'); - t.deepEqual(filterNonUnique([1, 2, 2, 3, 4, 4, 5]), [1,3,5], "Filters out the non-unique values in an array"); - //t.deepEqual(filterNonUnique(args..), 'Expected'); - //t.equal(filterNonUnique(args..), 'Expected'); - //t.false(filterNonUnique(args..), 'Expected'); - //t.throws(filterNonUnique(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof filterNonUnique === 'function', 'filterNonUnique is a Function'); + t.deepEqual(filterNonUnique([1, 2, 2, 3, 4, 4, 5]), [1,3,5], "Filters out the non-unique values in an array"); + //t.deepEqual(filterNonUnique(args..), 'Expected'); + //t.equal(filterNonUnique(args..), 'Expected'); + //t.false(filterNonUnique(args..), 'Expected'); + //t.throws(filterNonUnique(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/findKey/findKey.js b/test/findKey/findKey.js new file mode 100644 index 000000000..66a5edc1c --- /dev/null +++ b/test/findKey/findKey.js @@ -0,0 +1,2 @@ +const findKey = (obj, fn) => Object.keys(obj).find(key => fn(obj[key], key, obj)); +module.exports = findKey \ No newline at end of file diff --git a/test/findKey/findKey.test.js b/test/findKey/findKey.test.js new file mode 100644 index 000000000..d4b7870d0 --- /dev/null +++ b/test/findKey/findKey.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const findKey = require('./findKey.js'); + +test('Testing findKey', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof findKey === 'function', 'findKey is a Function'); + //t.deepEqual(findKey(args..), 'Expected'); + //t.equal(findKey(args..), 'Expected'); + //t.false(findKey(args..), 'Expected'); + //t.throws(findKey(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/findLast/findLast.js b/test/findLast/findLast.js index 00daa5d5d..1586a1b46 100644 --- a/test/findLast/findLast.js +++ b/test/findLast/findLast.js @@ -1,2 +1,2 @@ -const findLast = (arr, fn) => arr.filter(fn).slice(-1); - module.exports = findLast \ No newline at end of file +const findLast = (arr, fn) => arr.filter(fn).slice(-1)[0]; +module.exports = findLast \ No newline at end of file diff --git a/test/findLast/findLast.test.js b/test/findLast/findLast.test.js index 036d5f313..6e9ec236d 100644 --- a/test/findLast/findLast.test.js +++ b/test/findLast/findLast.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const findLast = require('./findLast.js'); test('Testing findLast', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof findLast === 'function', 'findLast is a Function'); - //t.deepEqual(findLast(args..), 'Expected'); - //t.equal(findLast(args..), 'Expected'); - //t.false(findLast(args..), 'Expected'); - //t.throws(findLast(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof findLast === 'function', 'findLast is a Function'); + //t.deepEqual(findLast(args..), 'Expected'); + //t.equal(findLast(args..), 'Expected'); + //t.false(findLast(args..), 'Expected'); + //t.throws(findLast(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/findLastIndex/findLastIndex.js b/test/findLastIndex/findLastIndex.js new file mode 100644 index 000000000..378a0e244 --- /dev/null +++ b/test/findLastIndex/findLastIndex.js @@ -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 \ No newline at end of file diff --git a/test/findLastIndex/findLastIndex.test.js b/test/findLastIndex/findLastIndex.test.js new file mode 100644 index 000000000..0791336b2 --- /dev/null +++ b/test/findLastIndex/findLastIndex.test.js @@ -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(); +}); \ No newline at end of file diff --git a/test/findLastKey/findLastKey.js b/test/findLastKey/findLastKey.js new file mode 100644 index 000000000..0033cf1e8 --- /dev/null +++ b/test/findLastKey/findLastKey.js @@ -0,0 +1,5 @@ +const findLastKey = (obj, fn) => +Object.keys(obj) +.reverse() +.find(key => fn(obj[key], key, obj)); +module.exports = findLastKey \ No newline at end of file diff --git a/test/findLastKey/findLastKey.test.js b/test/findLastKey/findLastKey.test.js new file mode 100644 index 000000000..f0e99a748 --- /dev/null +++ b/test/findLastKey/findLastKey.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const findLastKey = require('./findLastKey.js'); + +test('Testing findLastKey', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof findLastKey === 'function', 'findLastKey is a Function'); + //t.deepEqual(findLastKey(args..), 'Expected'); + //t.equal(findLastKey(args..), 'Expected'); + //t.false(findLastKey(args..), 'Expected'); + //t.throws(findLastKey(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/flatten/flatten.js b/test/flatten/flatten.js index 027441ea1..6563b70fd 100644 --- a/test/flatten/flatten.js +++ b/test/flatten/flatten.js @@ -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 \ No newline at end of file +module.exports = flatten \ No newline at end of file diff --git a/test/flatten/flatten.test.js b/test/flatten/flatten.test.js index e7741039f..eb54b6c19 100644 --- a/test/flatten/flatten.test.js +++ b/test/flatten/flatten.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const flatten = require('./flatten.js'); test('Testing flatten', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof flatten === 'function', 'flatten is a Function'); - t.deepEqual(flatten([1, [2], 3, 4]), [1, 2, 3, 4], "Flattens an array"); - t.deepEqual(flatten([1, [2, [3, [4, 5], 6], 7], 8], 2), [1, 2, 3, [4, 5], 6, 7, 8], "Flattens an array"); - //t.deepEqual(flatten(args..), 'Expected'); - //t.equal(flatten(args..), 'Expected'); - //t.false(flatten(args..), 'Expected'); - //t.throws(flatten(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof flatten === 'function', 'flatten is a Function'); + t.deepEqual(flatten([1, [2], 3, 4]), [1, 2, 3, 4], "Flattens an array"); + t.deepEqual(flatten([1, [2, [3, [4, 5], 6], 7], 8], 2), [1, 2, 3, [4, 5], 6, 7, 8], "Flattens an array"); + //t.deepEqual(flatten(args..), 'Expected'); + //t.equal(flatten(args..), 'Expected'); + //t.false(flatten(args..), 'Expected'); + //t.throws(flatten(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/flip/flip.js b/test/flip/flip.js index 1c3e94247..79d2e19e6 100644 --- a/test/flip/flip.js +++ b/test/flip/flip.js @@ -1,2 +1,2 @@ const flip = fn => (first, ...rest) => fn(...rest, first); - module.exports = flip \ No newline at end of file +module.exports = flip \ No newline at end of file diff --git a/test/flip/flip.test.js b/test/flip/flip.test.js index 664c5df50..25991568f 100644 --- a/test/flip/flip.test.js +++ b/test/flip/flip.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const flip = require('./flip.js'); test('Testing flip', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof flip === 'function', 'flip is a Function'); - //t.deepEqual(flip(args..), 'Expected'); - //t.equal(flip(args..), 'Expected'); - //t.false(flip(args..), 'Expected'); - //t.throws(flip(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof flip === 'function', 'flip is a Function'); + //t.deepEqual(flip(args..), 'Expected'); + //t.equal(flip(args..), 'Expected'); + //t.false(flip(args..), 'Expected'); + //t.throws(flip(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/forEachRight/forEachRight.js b/test/forEachRight/forEachRight.js index a6e0f7a9e..f23c83b8f 100644 --- a/test/forEachRight/forEachRight.js +++ b/test/forEachRight/forEachRight.js @@ -3,4 +3,4 @@ arr .slice(0) .reverse() .forEach(callback); - module.exports = forEachRight \ No newline at end of file +module.exports = forEachRight \ No newline at end of file diff --git a/test/forEachRight/forEachRight.test.js b/test/forEachRight/forEachRight.test.js index 286035dd6..75cfdec4b 100644 --- a/test/forEachRight/forEachRight.test.js +++ b/test/forEachRight/forEachRight.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const forEachRight = require('./forEachRight.js'); test('Testing forEachRight', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof forEachRight === 'function', 'forEachRight is a Function'); - //t.deepEqual(forEachRight(args..), 'Expected'); - //t.equal(forEachRight(args..), 'Expected'); - //t.false(forEachRight(args..), 'Expected'); - //t.throws(forEachRight(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof forEachRight === 'function', 'forEachRight is a Function'); + //t.deepEqual(forEachRight(args..), 'Expected'); + //t.equal(forEachRight(args..), 'Expected'); + //t.false(forEachRight(args..), 'Expected'); + //t.throws(forEachRight(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/forOwn/forOwn.js b/test/forOwn/forOwn.js new file mode 100644 index 000000000..52fdf433b --- /dev/null +++ b/test/forOwn/forOwn.js @@ -0,0 +1,2 @@ +const forOwn = (obj, fn) => Object.keys(obj).forEach(key => fn(obj[key], key, obj)); +module.exports = forOwn \ No newline at end of file diff --git a/test/forOwn/forOwn.test.js b/test/forOwn/forOwn.test.js new file mode 100644 index 000000000..5962d9ee4 --- /dev/null +++ b/test/forOwn/forOwn.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const forOwn = require('./forOwn.js'); + +test('Testing forOwn', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof forOwn === 'function', 'forOwn is a Function'); + //t.deepEqual(forOwn(args..), 'Expected'); + //t.equal(forOwn(args..), 'Expected'); + //t.false(forOwn(args..), 'Expected'); + //t.throws(forOwn(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/forOwnRight/forOwnRight.js b/test/forOwnRight/forOwnRight.js new file mode 100644 index 000000000..c29f23464 --- /dev/null +++ b/test/forOwnRight/forOwnRight.js @@ -0,0 +1,5 @@ +const forOwnRight = (obj, fn) => +Object.keys(obj) +.reverse() +.forEach(key => fn(obj[key], key, obj)); +module.exports = forOwnRight \ No newline at end of file diff --git a/test/forOwnRight/forOwnRight.test.js b/test/forOwnRight/forOwnRight.test.js new file mode 100644 index 000000000..ecd69a71c --- /dev/null +++ b/test/forOwnRight/forOwnRight.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const forOwnRight = require('./forOwnRight.js'); + +test('Testing forOwnRight', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof forOwnRight === 'function', 'forOwnRight is a Function'); + //t.deepEqual(forOwnRight(args..), 'Expected'); + //t.equal(forOwnRight(args..), 'Expected'); + //t.false(forOwnRight(args..), 'Expected'); + //t.throws(forOwnRight(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/formatDuration/formatDuration.js b/test/formatDuration/formatDuration.js index ae1075e92..ed0d60595 100644 --- a/test/formatDuration/formatDuration.js +++ b/test/formatDuration/formatDuration.js @@ -12,4 +12,4 @@ return Object.entries(time) .map(val => val[1] + ' ' + (val[1] !== 1 ? val[0] + 's' : val[0])) .join(', '); }; - module.exports = formatDuration \ No newline at end of file +module.exports = formatDuration \ No newline at end of file diff --git a/test/formatDuration/formatDuration.test.js b/test/formatDuration/formatDuration.test.js index 95708428a..6c5cc23c3 100644 --- a/test/formatDuration/formatDuration.test.js +++ b/test/formatDuration/formatDuration.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const formatDuration = require('./formatDuration.js'); test('Testing formatDuration', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof formatDuration === 'function', 'formatDuration is a Function'); - t.equal(formatDuration(1001), '1 second, 1 millisecond', "Returns the human readable format of the given number of milliseconds"); - t.equal(formatDuration(34325055574), '397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds', "Returns the human readable format of the given number of milliseconds"); - //t.deepEqual(formatDuration(args..), 'Expected'); - //t.equal(formatDuration(args..), 'Expected'); - //t.false(formatDuration(args..), 'Expected'); - //t.throws(formatDuration(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof formatDuration === 'function', 'formatDuration is a Function'); + t.equal(formatDuration(1001), '1 second, 1 millisecond', "Returns the human readable format of the given number of milliseconds"); + t.equal(formatDuration(34325055574), '397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds', "Returns the human readable format of the given number of milliseconds"); + //t.deepEqual(formatDuration(args..), 'Expected'); + //t.equal(formatDuration(args..), 'Expected'); + //t.false(formatDuration(args..), 'Expected'); + //t.throws(formatDuration(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/fromCamelCase/fromCamelCase.js b/test/fromCamelCase/fromCamelCase.js index 10c6fac30..3538c0f2e 100644 --- a/test/fromCamelCase/fromCamelCase.js +++ b/test/fromCamelCase/fromCamelCase.js @@ -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 \ No newline at end of file +module.exports = fromCamelCase \ No newline at end of file diff --git a/test/fromCamelCase/fromCamelCase.test.js b/test/fromCamelCase/fromCamelCase.test.js index 73ea04316..58ecffed9 100644 --- a/test/fromCamelCase/fromCamelCase.test.js +++ b/test/fromCamelCase/fromCamelCase.test.js @@ -2,15 +2,15 @@ const test = require('tape'); const fromCamelCase = require('./fromCamelCase.js'); test('Testing fromCamelCase', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof fromCamelCase === 'function', 'fromCamelCase is a Function'); - t.equal(fromCamelCase('someDatabaseFieldName', ' '), 'some database field name', "Converts a string from camelcase"); - t.equal(fromCamelCase('someLabelThatNeedsToBeCamelized', '-'), 'some-label-that-needs-to-be-camelized', "Converts a string from camelcase"); - t.equal(fromCamelCase('someJavascriptProperty', '_'), 'some_javascript_property', "Converts a string from camelcase"); - //t.deepEqual(fromCamelCase(args..), 'Expected'); - //t.equal(fromCamelCase(args..), 'Expected'); - //t.false(fromCamelCase(args..), 'Expected'); - //t.throws(fromCamelCase(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof fromCamelCase === 'function', 'fromCamelCase is a Function'); + t.equal(fromCamelCase('someDatabaseFieldName', ' '), 'some database field name', "Converts a string from camelcase"); + t.equal(fromCamelCase('someLabelThatNeedsToBeCamelized', '-'), 'some-label-that-needs-to-be-camelized', "Converts a string from camelcase"); + t.equal(fromCamelCase('someJavascriptProperty', '_'), 'some_javascript_property', "Converts a string from camelcase"); + //t.deepEqual(fromCamelCase(args..), 'Expected'); + //t.equal(fromCamelCase(args..), 'Expected'); + //t.false(fromCamelCase(args..), 'Expected'); + //t.throws(fromCamelCase(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/functionName/functionName.js b/test/functionName/functionName.js index 2181fe74a..ffca87364 100644 --- a/test/functionName/functionName.js +++ b/test/functionName/functionName.js @@ -1,2 +1,2 @@ const functionName = fn => (console.debug(fn.name), fn); - module.exports = functionName \ No newline at end of file +module.exports = functionName \ No newline at end of file diff --git a/test/functionName/functionName.test.js b/test/functionName/functionName.test.js index f377cb49f..d2a5d41d4 100644 --- a/test/functionName/functionName.test.js +++ b/test/functionName/functionName.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const functionName = require('./functionName.js'); test('Testing functionName', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof functionName === 'function', 'functionName is a Function'); - //t.deepEqual(functionName(args..), 'Expected'); - //t.equal(functionName(args..), 'Expected'); - //t.false(functionName(args..), 'Expected'); - //t.throws(functionName(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof functionName === 'function', 'functionName is a Function'); + //t.deepEqual(functionName(args..), 'Expected'); + //t.equal(functionName(args..), 'Expected'); + //t.false(functionName(args..), 'Expected'); + //t.throws(functionName(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/functions/functions.js b/test/functions/functions.js index 7a451527d..93e11a78a 100644 --- a/test/functions/functions.js +++ b/test/functions/functions.js @@ -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 \ No newline at end of file +module.exports = functions \ No newline at end of file diff --git a/test/functions/functions.test.js b/test/functions/functions.test.js index 8590341fb..a47314d11 100644 --- a/test/functions/functions.test.js +++ b/test/functions/functions.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const functions = require('./functions.js'); test('Testing functions', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof functions === 'function', 'functions is a Function'); - //t.deepEqual(functions(args..), 'Expected'); - //t.equal(functions(args..), 'Expected'); - //t.false(functions(args..), 'Expected'); - //t.throws(functions(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof functions === 'function', 'functions is a Function'); + //t.deepEqual(functions(args..), 'Expected'); + //t.equal(functions(args..), 'Expected'); + //t.false(functions(args..), 'Expected'); + //t.throws(functions(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/gcd/gcd.js b/test/gcd/gcd.js index 201d996ae..877cd3763 100644 --- a/test/gcd/gcd.js +++ b/test/gcd/gcd.js @@ -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 \ No newline at end of file +module.exports = gcd \ No newline at end of file diff --git a/test/gcd/gcd.test.js b/test/gcd/gcd.test.js index 8ed4650a8..a222fe04b 100644 --- a/test/gcd/gcd.test.js +++ b/test/gcd/gcd.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const gcd = require('./gcd.js'); test('Testing gcd', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof gcd === 'function', 'gcd is a Function'); - t.equal(gcd(8, 36), 4, "Calculates the greatest common divisor between two or more numbers/arrays"); - t.deepEqual(gcd(...[12, 8, 32]), 4, "Calculates the greatest common divisor between two or more numbers/arrays"); - //t.deepEqual(gcd(args..), 'Expected'); - //t.equal(gcd(args..), 'Expected'); - //t.false(gcd(args..), 'Expected'); - //t.throws(gcd(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof gcd === 'function', 'gcd is a Function'); + t.equal(gcd(8, 36), 4, "Calculates the greatest common divisor between two or more numbers/arrays"); + t.deepEqual(gcd(...[12, 8, 32]), 4, "Calculates the greatest common divisor between two or more numbers/arrays"); + //t.deepEqual(gcd(args..), 'Expected'); + //t.equal(gcd(args..), 'Expected'); + //t.false(gcd(args..), 'Expected'); + //t.throws(gcd(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/geometricProgression/geometricProgression.js b/test/geometricProgression/geometricProgression.js index c42691c59..afaeaf136 100644 --- a/test/geometricProgression/geometricProgression.js +++ b/test/geometricProgression/geometricProgression.js @@ -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 \ No newline at end of file +module.exports = geometricProgression \ No newline at end of file diff --git a/test/geometricProgression/geometricProgression.test.js b/test/geometricProgression/geometricProgression.test.js index 09fb3093d..059e83682 100644 --- a/test/geometricProgression/geometricProgression.test.js +++ b/test/geometricProgression/geometricProgression.test.js @@ -2,15 +2,15 @@ const test = require('tape'); const geometricProgression = require('./geometricProgression.js'); test('Testing geometricProgression', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof geometricProgression === 'function', 'geometricProgression is a Function'); - t.deepEqual(geometricProgression(256), [1, 2, 4, 8, 16, 32, 64, 128, 256], "Initializes an array containing the numbers in the specified range"); - t.deepEqual(geometricProgression(256, 3), [3, 6, 12, 24, 48, 96, 192], "Initializes an array containing the numbers in the specified range"); - t.deepEqual(geometricProgression(256, 1, 4), [1, 4, 16, 64, 256], "Initializes an array containing the numbers in the specified range"); - //t.deepEqual(geometricProgression(args..), 'Expected'); - //t.equal(geometricProgression(args..), 'Expected'); - //t.false(geometricProgression(args..), 'Expected'); - //t.throws(geometricProgression(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof geometricProgression === 'function', 'geometricProgression is a Function'); + t.deepEqual(geometricProgression(256), [1, 2, 4, 8, 16, 32, 64, 128, 256], "Initializes an array containing the numbers in the specified range"); + t.deepEqual(geometricProgression(256, 3), [3, 6, 12, 24, 48, 96, 192], "Initializes an array containing the numbers in the specified range"); + t.deepEqual(geometricProgression(256, 1, 4), [1, 4, 16, 64, 256], "Initializes an array containing the numbers in the specified range"); + //t.deepEqual(geometricProgression(args..), 'Expected'); + //t.equal(geometricProgression(args..), 'Expected'); + //t.false(geometricProgression(args..), 'Expected'); + //t.throws(geometricProgression(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/get/get.js b/test/get/get.js index b83862c51..568160c84 100644 --- a/test/get/get.js +++ b/test/get/get.js @@ -6,4 +6,4 @@ s .filter(t => t !== '') .reduce((prev, cur) => prev && prev[cur], from) ); - module.exports = get \ No newline at end of file +module.exports = get \ No newline at end of file diff --git a/test/get/get.test.js b/test/get/get.test.js index fbe638391..d8448a171 100644 --- a/test/get/get.test.js +++ b/test/get/get.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const get = require('./get.js'); test('Testing get', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof get === 'function', 'get is a Function'); - const obj = { selector: { to: { val: 'val to get' } } }; - t.deepEqual(get(obj, 'selector.to.val'), ['val to get'], "Retrieve a property indicated by the selector from an object."); - //t.deepEqual(get(args..), 'Expected'); - //t.equal(get(args..), 'Expected'); - //t.false(get(args..), 'Expected'); - //t.throws(get(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof get === 'function', 'get is a Function'); + const obj = { selector: { to: { val: 'val to get' } } }; + t.deepEqual(get(obj, 'selector.to.val'), ['val to get'], "Retrieve a property indicated by the selector from an object."); + //t.deepEqual(get(args..), 'Expected'); + //t.equal(get(args..), 'Expected'); + //t.false(get(args..), 'Expected'); + //t.throws(get(args..), 'Expected'); + t.end(); }); diff --git a/test/getDaysDiffBetweenDates/getDaysDiffBetweenDates.js b/test/getDaysDiffBetweenDates/getDaysDiffBetweenDates.js index e2157f0d3..899f75ae4 100644 --- a/test/getDaysDiffBetweenDates/getDaysDiffBetweenDates.js +++ b/test/getDaysDiffBetweenDates/getDaysDiffBetweenDates.js @@ -1,3 +1,3 @@ const getDaysDiffBetweenDates = (dateInitial, dateFinal) => (dateFinal - dateInitial) / (1000 * 3600 * 24); - module.exports = getDaysDiffBetweenDates \ No newline at end of file +module.exports = getDaysDiffBetweenDates \ No newline at end of file diff --git a/test/getDaysDiffBetweenDates/getDaysDiffBetweenDates.test.js b/test/getDaysDiffBetweenDates/getDaysDiffBetweenDates.test.js index 39633f863..56bf82f8c 100644 --- a/test/getDaysDiffBetweenDates/getDaysDiffBetweenDates.test.js +++ b/test/getDaysDiffBetweenDates/getDaysDiffBetweenDates.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const getDaysDiffBetweenDates = require('./getDaysDiffBetweenDates.js'); test('Testing getDaysDiffBetweenDates', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof getDaysDiffBetweenDates === 'function', 'getDaysDiffBetweenDates is a Function'); - t.equal(getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22')), 9, "Returns the difference in days between two dates"); - //t.deepEqual(getDaysDiffBetweenDates(args..), 'Expected'); - //t.equal(getDaysDiffBetweenDates(args..), 'Expected'); - //t.false(getDaysDiffBetweenDates(args..), 'Expected'); - //t.throws(getDaysDiffBetweenDates(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof getDaysDiffBetweenDates === 'function', 'getDaysDiffBetweenDates is a Function'); + t.equal(getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22')), 9, "Returns the difference in days between two dates"); + //t.deepEqual(getDaysDiffBetweenDates(args..), 'Expected'); + //t.equal(getDaysDiffBetweenDates(args..), 'Expected'); + //t.false(getDaysDiffBetweenDates(args..), 'Expected'); + //t.throws(getDaysDiffBetweenDates(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/getScrollPosition/getScrollPosition.js b/test/getScrollPosition/getScrollPosition.js index 4d3e12a62..a5fa12a18 100644 --- a/test/getScrollPosition/getScrollPosition.js +++ b/test/getScrollPosition/getScrollPosition.js @@ -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 \ No newline at end of file +module.exports = getScrollPosition \ No newline at end of file diff --git a/test/getScrollPosition/getScrollPosition.test.js b/test/getScrollPosition/getScrollPosition.test.js index ef46dac55..ded20c020 100644 --- a/test/getScrollPosition/getScrollPosition.test.js +++ b/test/getScrollPosition/getScrollPosition.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const getScrollPosition = require('./getScrollPosition.js'); test('Testing getScrollPosition', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof getScrollPosition === 'function', 'getScrollPosition is a Function'); - //t.deepEqual(getScrollPosition(args..), 'Expected'); - //t.equal(getScrollPosition(args..), 'Expected'); - //t.false(getScrollPosition(args..), 'Expected'); - //t.throws(getScrollPosition(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof getScrollPosition === 'function', 'getScrollPosition is a Function'); + //t.deepEqual(getScrollPosition(args..), 'Expected'); + //t.equal(getScrollPosition(args..), 'Expected'); + //t.false(getScrollPosition(args..), 'Expected'); + //t.throws(getScrollPosition(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/getStyle/getStyle.js b/test/getStyle/getStyle.js index 6df1c1394..6303f0993 100644 --- a/test/getStyle/getStyle.js +++ b/test/getStyle/getStyle.js @@ -1,2 +1,2 @@ const getStyle = (el, ruleName) => getComputedStyle(el)[ruleName]; - module.exports = getStyle \ No newline at end of file +module.exports = getStyle \ No newline at end of file diff --git a/test/getStyle/getStyle.test.js b/test/getStyle/getStyle.test.js index 6fed01e98..11c2c9244 100644 --- a/test/getStyle/getStyle.test.js +++ b/test/getStyle/getStyle.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const getStyle = require('./getStyle.js'); test('Testing getStyle', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof getStyle === 'function', 'getStyle is a Function'); - //t.deepEqual(getStyle(args..), 'Expected'); - //t.equal(getStyle(args..), 'Expected'); - //t.false(getStyle(args..), 'Expected'); - //t.throws(getStyle(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof getStyle === 'function', 'getStyle is a Function'); + //t.deepEqual(getStyle(args..), 'Expected'); + //t.equal(getStyle(args..), 'Expected'); + //t.false(getStyle(args..), 'Expected'); + //t.throws(getStyle(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/getType/getType.js b/test/getType/getType.js index 02973563b..8c9f93a75 100644 --- a/test/getType/getType.js +++ b/test/getType/getType.js @@ -1,3 +1,3 @@ const getType = v => v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase(); - module.exports = getType \ No newline at end of file +module.exports = getType \ No newline at end of file diff --git a/test/getType/getType.test.js b/test/getType/getType.test.js index 2ae35510b..359e9ea07 100644 --- a/test/getType/getType.test.js +++ b/test/getType/getType.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const getType = require('./getType.js'); test('Testing getType', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof getType === 'function', 'getType is a Function'); - t.equal(getType(new Set([1, 2, 3])), 'set', "Returns the native type of a value"); - //t.deepEqual(getType(args..), 'Expected'); - //t.equal(getType(args..), 'Expected'); - //t.false(getType(args..), 'Expected'); - //t.throws(getType(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof getType === 'function', 'getType is a Function'); + t.equal(getType(new Set([1, 2, 3])), 'set', "Returns the native type of a value"); + //t.deepEqual(getType(args..), 'Expected'); + //t.equal(getType(args..), 'Expected'); + //t.false(getType(args..), 'Expected'); + //t.throws(getType(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/getURLParameters/getURLParameters.js b/test/getURLParameters/getURLParameters.js index 029711f48..622c99769 100644 --- a/test/getURLParameters/getURLParameters.js +++ b/test/getURLParameters/getURLParameters.js @@ -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 \ No newline at end of file +module.exports = getURLParameters \ No newline at end of file diff --git a/test/getURLParameters/getURLParameters.test.js b/test/getURLParameters/getURLParameters.test.js index 4c9463228..a030f86ee 100644 --- a/test/getURLParameters/getURLParameters.test.js +++ b/test/getURLParameters/getURLParameters.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const getURLParameters = require('./getURLParameters.js'); test('Testing getURLParameters', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof getURLParameters === 'function', 'getURLParameters is a Function'); - t.deepEqual(getURLParameters('http://url.com/page?name=Adam&surname=Smith'), {name: 'Adam', surname: 'Smith'}, "Returns an object containing the parameters of the current URL"); - //t.deepEqual(getURLParameters(args..), 'Expected'); - //t.equal(getURLParameters(args..), 'Expected'); - //t.false(getURLParameters(args..), 'Expected'); - //t.throws(getURLParameters(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof getURLParameters === 'function', 'getURLParameters is a Function'); + t.deepEqual(getURLParameters('http://url.com/page?name=Adam&surname=Smith'), {name: 'Adam', surname: 'Smith'}, "Returns an object containing the parameters of the current URL"); + //t.deepEqual(getURLParameters(args..), 'Expected'); + //t.equal(getURLParameters(args..), 'Expected'); + //t.false(getURLParameters(args..), 'Expected'); + //t.throws(getURLParameters(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/groupBy/groupBy.js b/test/groupBy/groupBy.js index f1083e4fe..25bb573d9 100644 --- a/test/groupBy/groupBy.js +++ b/test/groupBy/groupBy.js @@ -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 \ No newline at end of file +module.exports = groupBy \ No newline at end of file diff --git a/test/groupBy/groupBy.test.js b/test/groupBy/groupBy.test.js index 1470c4070..e3e8528bb 100644 --- a/test/groupBy/groupBy.test.js +++ b/test/groupBy/groupBy.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const groupBy = require('./groupBy.js'); test('Testing groupBy', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof groupBy === 'function', 'groupBy is a Function'); - t.deepEqual(groupBy([6.1, 4.2, 6.3], Math.floor), {4: [4.2], 6: [6.1, 6.3]}, "Groups the elements of an array based on the given function"); - t.deepEqual(groupBy(['one', 'two', 'three'], 'length'), {3: ['one', 'two'], 5: ['three']}, "Groups the elements of an array based on the given function"); - //t.deepEqual(groupBy(args..), 'Expected'); - //t.equal(groupBy(args..), 'Expected'); - //t.false(groupBy(args..), 'Expected'); - //t.throws(groupBy(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof groupBy === 'function', 'groupBy is a Function'); + t.deepEqual(groupBy([6.1, 4.2, 6.3], Math.floor), {4: [4.2], 6: [6.1, 6.3]}, "Groups the elements of an array based on the given function"); + t.deepEqual(groupBy(['one', 'two', 'three'], 'length'), {3: ['one', 'two'], 5: ['three']}, "Groups the elements of an array based on the given function"); + //t.deepEqual(groupBy(args..), 'Expected'); + //t.equal(groupBy(args..), 'Expected'); + //t.false(groupBy(args..), 'Expected'); + //t.throws(groupBy(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/hammingDistance/hammingDistance.js b/test/hammingDistance/hammingDistance.js index e6e4c81e0..356304ed4 100644 --- a/test/hammingDistance/hammingDistance.js +++ b/test/hammingDistance/hammingDistance.js @@ -1,2 +1,2 @@ const hammingDistance = (num1, num2) => ((num1 ^ num2).toString(2).match(/1/g) || '').length; - module.exports = hammingDistance \ No newline at end of file +module.exports = hammingDistance \ No newline at end of file diff --git a/test/hammingDistance/hammingDistance.test.js b/test/hammingDistance/hammingDistance.test.js index 503ddde36..6ada1733c 100644 --- a/test/hammingDistance/hammingDistance.test.js +++ b/test/hammingDistance/hammingDistance.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const hammingDistance = require('./hammingDistance.js'); test('Testing hammingDistance', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof hammingDistance === 'function', 'hammingDistance is a Function'); - t.equal(hammingDistance(2, 3), 1, "retuns hamming disance between 2 values"); - //t.deepEqual(hammingDistance(args..), 'Expected'); - //t.equal(hammingDistance(args..), 'Expected'); - //t.false(hammingDistance(args..), 'Expected'); - //t.throws(hammingDistance(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof hammingDistance === 'function', 'hammingDistance is a Function'); + t.equal(hammingDistance(2, 3), 1, "retuns hamming disance between 2 values"); + //t.deepEqual(hammingDistance(args..), 'Expected'); + //t.equal(hammingDistance(args..), 'Expected'); + //t.false(hammingDistance(args..), 'Expected'); + //t.throws(hammingDistance(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/hasClass/hasClass.js b/test/hasClass/hasClass.js index 8f6f09234..c14590500 100644 --- a/test/hasClass/hasClass.js +++ b/test/hasClass/hasClass.js @@ -1,2 +1,2 @@ const hasClass = (el, className) => el.classList.contains(className); - module.exports = hasClass \ No newline at end of file +module.exports = hasClass \ No newline at end of file diff --git a/test/hasFlags/hasFlags.js b/test/hasFlags/hasFlags.js index c0312e5fc..9b8740692 100644 --- a/test/hasFlags/hasFlags.js +++ b/test/hasFlags/hasFlags.js @@ -1,3 +1,3 @@ const hasFlags = (...flags) => flags.every(flag => process.argv.includes(/^-{1,2}/.test(flag) ? flag : '--' + flag)); - module.exports = hasFlags \ No newline at end of file +module.exports = hasFlags \ No newline at end of file diff --git a/test/hasFlags/hasFlags.test.js b/test/hasFlags/hasFlags.test.js index 9425e55d9..0245051be 100644 --- a/test/hasFlags/hasFlags.test.js +++ b/test/hasFlags/hasFlags.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const hasFlags = require('./hasFlags.js'); test('Testing hasFlags', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof hasFlags === 'function', 'hasFlags is a Function'); - //t.deepEqual(hasFlags(args..), 'Expected'); - //t.equal(hasFlags(args..), 'Expected'); - //t.false(hasFlags(args..), 'Expected'); - //t.throws(hasFlags(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof hasFlags === 'function', 'hasFlags is a Function'); + //t.deepEqual(hasFlags(args..), 'Expected'); + //t.equal(hasFlags(args..), 'Expected'); + //t.false(hasFlags(args..), 'Expected'); + //t.throws(hasFlags(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/hashBrowser/hashBrowser.js b/test/hashBrowser/hashBrowser.js index 59db15021..ea13e46a2 100644 --- a/test/hashBrowser/hashBrowser.js +++ b/test/hashBrowser/hashBrowser.js @@ -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 \ No newline at end of file +module.exports = hashBrowser \ No newline at end of file diff --git a/test/hashBrowser/hashBrowser.test.js b/test/hashBrowser/hashBrowser.test.js index 93ad07918..d01cafc5b 100644 --- a/test/hashBrowser/hashBrowser.test.js +++ b/test/hashBrowser/hashBrowser.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const hashBrowser = require('./hashBrowser.js'); test('Testing hashBrowser', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof hashBrowser === 'function', 'hashBrowser is a Function'); - //t.deepEqual(hashBrowser(args..), 'Expected'); - //t.equal(hashBrowser(args..), 'Expected'); - //t.false(hashBrowser(args..), 'Expected'); - //t.throws(hashBrowser(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof hashBrowser === 'function', 'hashBrowser is a Function'); + //t.deepEqual(hashBrowser(args..), 'Expected'); + //t.equal(hashBrowser(args..), 'Expected'); + //t.false(hashBrowser(args..), 'Expected'); + //t.throws(hashBrowser(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/hashNode/hashNode.js b/test/hashNode/hashNode.js index e6124fe5d..9041dec36 100644 --- a/test/hashNode/hashNode.js +++ b/test/hashNode/hashNode.js @@ -12,4 +12,4 @@ crypto 0 ) ); - module.exports = hashNode \ No newline at end of file +module.exports = hashNode \ No newline at end of file diff --git a/test/hashNode/hashNode.test.js b/test/hashNode/hashNode.test.js index 31d0a0324..e89dafe9e 100644 --- a/test/hashNode/hashNode.test.js +++ b/test/hashNode/hashNode.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const hashNode = require('./hashNode.js'); test('Testing hashNode', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof hashNode === 'function', 'hashNode is a Function'); - //t.deepEqual(hashNode(args..), 'Expected'); - //t.equal(hashNode(args..), 'Expected'); - //t.false(hashNode(args..), 'Expected'); - //t.throws(hashNode(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof hashNode === 'function', 'hashNode is a Function'); + //t.deepEqual(hashNode(args..), 'Expected'); + //t.equal(hashNode(args..), 'Expected'); + //t.false(hashNode(args..), 'Expected'); + //t.throws(hashNode(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/head/head.js b/test/head/head.js index 0c4e9eb90..bf2039dd0 100644 --- a/test/head/head.js +++ b/test/head/head.js @@ -1,2 +1,2 @@ const head = arr => arr[0]; - module.exports = head \ No newline at end of file +module.exports = head \ No newline at end of file diff --git a/test/head/head.test.js b/test/head/head.test.js index 7cf67cd9c..b6fa2d188 100644 --- a/test/head/head.test.js +++ b/test/head/head.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const head = require('./head.js'); test('Testing head', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape t.true(typeof head === 'function', 'head is a Function'); t.true(head({ a: 1234}) === undefined, 'head({ a: 1234}) returns undefined'); t.equal(head([1, 2, 3]), 1, "head([1, 2, 3]) returns 1"); t.equal(head({ 0: false}), false, 'head({ 0: false}) returns false'); - t.equal(head('String'), 'S', 'head(String) returns S'); + t.equal(head('String'), 'S', 'head(String) returns S'); t.throws(() => head(null), 'head(null) throws an Error'); t.throws(() => head(undefined), 'head(undefined) throws an Error'); t.throws(() => head(), 'head() throws an Error'); @@ -17,5 +17,5 @@ test('Testing head', (t) => { head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]); let end = new Date().getTime(); t.true((end - start) < 2000, 'head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run'); - t.end(); + t.end(); }); \ No newline at end of file diff --git a/test/hexToRGB/hexToRGB.js b/test/hexToRGB/hexToRGB.js index 090ec2a35..516050b8a 100644 --- a/test/hexToRGB/hexToRGB.js +++ b/test/hexToRGB/hexToRGB.js @@ -17,4 +17,4 @@ return ( ')' ); }; - module.exports = hexToRGB \ No newline at end of file +module.exports = hexToRGB \ No newline at end of file diff --git a/test/hexToRGB/hexToRGB.test.js b/test/hexToRGB/hexToRGB.test.js index b3f6a7c4b..4b3d0fdd8 100644 --- a/test/hexToRGB/hexToRGB.test.js +++ b/test/hexToRGB/hexToRGB.test.js @@ -2,15 +2,15 @@ const test = require('tape'); const hexToRGB = require('./hexToRGB.js'); test('Testing hexToRGB', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof hexToRGB === 'function', 'hexToRGB is a Function'); - t.equal(hexToRGB('#27ae60ff'), 'rgba(39, 174, 96, 255)', "Converts a color code to a rgb() or rgba() string"); - t.equal(hexToRGB('27ae60'), 'rgb(39, 174, 96)', "Converts a color code to a rgb() or rgba() string"); - t.equal(hexToRGB('#fff'), 'rgb(255, 255, 255)', "Converts a color code to a rgb() or rgba() string"); - //t.deepEqual(hexToRGB(args..), 'Expected'); - //t.equal(hexToRGB(args..), 'Expected'); - //t.false(hexToRGB(args..), 'Expected'); - //t.throws(hexToRGB(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof hexToRGB === 'function', 'hexToRGB is a Function'); + t.equal(hexToRGB('#27ae60ff'), 'rgba(39, 174, 96, 255)', "Converts a color code to a rgb() or rgba() string"); + t.equal(hexToRGB('27ae60'), 'rgb(39, 174, 96)', "Converts a color code to a rgb() or rgba() string"); + t.equal(hexToRGB('#fff'), 'rgb(255, 255, 255)', "Converts a color code to a rgb() or rgba() string"); + //t.deepEqual(hexToRGB(args..), 'Expected'); + //t.equal(hexToRGB(args..), 'Expected'); + //t.false(hexToRGB(args..), 'Expected'); + //t.throws(hexToRGB(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/hide/hide.js b/test/hide/hide.js index 56bc848c9..d16add1ce 100644 --- a/test/hide/hide.js +++ b/test/hide/hide.js @@ -1,2 +1,2 @@ const hide = (...el) => [...el].forEach(e => (e.style.display = 'none')); - module.exports = hide \ No newline at end of file +module.exports = hide \ No newline at end of file diff --git a/test/hide/hide.test.js b/test/hide/hide.test.js index 9746171a3..d93d3fa74 100644 --- a/test/hide/hide.test.js +++ b/test/hide/hide.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const hide = require('./hide.js'); test('Testing hide', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof hide === 'function', 'hide is a Function'); - //t.deepEqual(hide(args..), 'Expected'); - //t.equal(hide(args..), 'Expected'); - //t.false(hide(args..), 'Expected'); - //t.throws(hide(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof hide === 'function', 'hide is a Function'); + //t.deepEqual(hide(args..), 'Expected'); + //t.equal(hide(args..), 'Expected'); + //t.false(hide(args..), 'Expected'); + //t.throws(hide(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/howManyTimes/howManyTimes.js b/test/howManyTimes/howManyTimes.js index 85d57b0d5..51313c194 100644 --- a/test/howManyTimes/howManyTimes.js +++ b/test/howManyTimes/howManyTimes.js @@ -8,4 +8,4 @@ num = num / divisor; } return i; }; - module.exports = howManyTimes \ No newline at end of file +module.exports = howManyTimes \ No newline at end of file diff --git a/test/howManyTimes/howManyTimes.test.js b/test/howManyTimes/howManyTimes.test.js index 98fc00b85..250b542ce 100644 --- a/test/howManyTimes/howManyTimes.test.js +++ b/test/howManyTimes/howManyTimes.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const howManyTimes = require('./howManyTimes.js'); test('Testing howManyTimes', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof howManyTimes === 'function', 'howManyTimes is a Function'); - //t.deepEqual(howManyTimes(args..), 'Expected'); - //t.equal(howManyTimes(args..), 'Expected'); - //t.false(howManyTimes(args..), 'Expected'); - //t.throws(howManyTimes(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof howManyTimes === 'function', 'howManyTimes is a Function'); + //t.deepEqual(howManyTimes(args..), 'Expected'); + //t.equal(howManyTimes(args..), 'Expected'); + //t.false(howManyTimes(args..), 'Expected'); + //t.throws(howManyTimes(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/httpDelete/httpDelete.js b/test/httpDelete/httpDelete.js index 8a3ff97e6..0892b1819 100644 --- a/test/httpDelete/httpDelete.js +++ b/test/httpDelete/httpDelete.js @@ -5,4 +5,4 @@ request.onload = () => callback(request); request.onerror = () => err(request); request.send(); }; - module.exports = httpDelete \ No newline at end of file +module.exports = httpDelete \ No newline at end of file diff --git a/test/httpDelete/httpDelete.test.js b/test/httpDelete/httpDelete.test.js index 862230e23..d4edd42a9 100644 --- a/test/httpDelete/httpDelete.test.js +++ b/test/httpDelete/httpDelete.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const httpDelete = require('./httpDelete.js'); test('Testing httpDelete', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof httpDelete === 'function', 'httpDelete is a Function'); - //t.deepEqual(httpDelete(args..), 'Expected'); - //t.equal(httpDelete(args..), 'Expected'); - //t.false(httpDelete(args..), 'Expected'); - //t.throws(httpDelete(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof httpDelete === 'function', 'httpDelete is a Function'); + //t.deepEqual(httpDelete(args..), 'Expected'); + //t.equal(httpDelete(args..), 'Expected'); + //t.false(httpDelete(args..), 'Expected'); + //t.throws(httpDelete(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/httpGet/httpGet.js b/test/httpGet/httpGet.js index 04564234a..413049085 100644 --- a/test/httpGet/httpGet.js +++ b/test/httpGet/httpGet.js @@ -5,4 +5,4 @@ request.onload = () => callback(request.responseText); request.onerror = () => err(request); request.send(); }; - module.exports = httpGet \ No newline at end of file +module.exports = httpGet \ No newline at end of file diff --git a/test/httpGet/httpGet.test.js b/test/httpGet/httpGet.test.js index c55559714..22a743776 100644 --- a/test/httpGet/httpGet.test.js +++ b/test/httpGet/httpGet.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const httpGet = require('./httpGet.js'); test('Testing httpGet', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof httpGet === 'function', 'httpGet is a Function'); - //t.deepEqual(httpGet(args..), 'Expected'); - //t.equal(httpGet(args..), 'Expected'); - //t.false(httpGet(args..), 'Expected'); - //t.throws(httpGet(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof httpGet === 'function', 'httpGet is a Function'); + //t.deepEqual(httpGet(args..), 'Expected'); + //t.equal(httpGet(args..), 'Expected'); + //t.false(httpGet(args..), 'Expected'); + //t.throws(httpGet(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/httpPost/httpPost.js b/test/httpPost/httpPost.js index bb7345f83..e81331645 100644 --- a/test/httpPost/httpPost.js +++ b/test/httpPost/httpPost.js @@ -6,4 +6,4 @@ request.onload = () => callback(request.responseText); request.onerror = () => err(request); request.send(data); }; - module.exports = httpPost \ No newline at end of file +module.exports = httpPost \ No newline at end of file diff --git a/test/httpPost/httpPost.test.js b/test/httpPost/httpPost.test.js index df8add407..6b291825f 100644 --- a/test/httpPost/httpPost.test.js +++ b/test/httpPost/httpPost.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const httpPost = require('./httpPost.js'); test('Testing httpPost', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof httpPost === 'function', 'httpPost is a Function'); - //t.deepEqual(httpPost(args..), 'Expected'); - //t.equal(httpPost(args..), 'Expected'); - //t.false(httpPost(args..), 'Expected'); - //t.throws(httpPost(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof httpPost === 'function', 'httpPost is a Function'); + //t.deepEqual(httpPost(args..), 'Expected'); + //t.equal(httpPost(args..), 'Expected'); + //t.false(httpPost(args..), 'Expected'); + //t.throws(httpPost(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/httpPut/httpPut.js b/test/httpPut/httpPut.js index fba715694..71a0f79d9 100644 --- a/test/httpPut/httpPut.js +++ b/test/httpPut/httpPut.js @@ -6,4 +6,4 @@ request.onload = () => callback(request); request.onerror = () => err(request); request.send(data); }; - module.exports = httpPut \ No newline at end of file +module.exports = httpPut \ No newline at end of file diff --git a/test/httpPut/httpPut.test.js b/test/httpPut/httpPut.test.js index 1ca28c87d..d7c3f1e86 100644 --- a/test/httpPut/httpPut.test.js +++ b/test/httpPut/httpPut.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const httpPut = require('./httpPut.js'); test('Testing httpPut', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof httpPut === 'function', 'httpPut is a Function'); - //t.deepEqual(httpPut(args..), 'Expected'); - //t.equal(httpPut(args..), 'Expected'); - //t.false(httpPut(args..), 'Expected'); - //t.throws(httpPut(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof httpPut === 'function', 'httpPut is a Function'); + //t.deepEqual(httpPut(args..), 'Expected'); + //t.equal(httpPut(args..), 'Expected'); + //t.false(httpPut(args..), 'Expected'); + //t.throws(httpPut(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/httpsRedirect/httpsRedirect.js b/test/httpsRedirect/httpsRedirect.js index 832563f07..c1e3d2c5a 100644 --- a/test/httpsRedirect/httpsRedirect.js +++ b/test/httpsRedirect/httpsRedirect.js @@ -1,4 +1,4 @@ const httpsRedirect = () => { if (location.protocol !== 'https:') location.replace('https://' + location.href.split('//')[1]); }; - module.exports = httpsRedirect \ No newline at end of file +module.exports = httpsRedirect \ No newline at end of file diff --git a/test/httpsRedirect/httpsRedirect.test.js b/test/httpsRedirect/httpsRedirect.test.js index dbd08805a..20f70d654 100644 --- a/test/httpsRedirect/httpsRedirect.test.js +++ b/test/httpsRedirect/httpsRedirect.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const httpsRedirect = require('./httpsRedirect.js'); test('Testing httpsRedirect', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof httpsRedirect === 'function', 'httpsRedirect is a Function'); - //t.deepEqual(httpsRedirect(args..), 'Expected'); - //t.equal(httpsRedirect(args..), 'Expected'); - //t.false(httpsRedirect(args..), 'Expected'); - //t.throws(httpsRedirect(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof httpsRedirect === 'function', 'httpsRedirect is a Function'); + //t.deepEqual(httpsRedirect(args..), 'Expected'); + //t.equal(httpsRedirect(args..), 'Expected'); + //t.false(httpsRedirect(args..), 'Expected'); + //t.throws(httpsRedirect(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/inRange/inRange.js b/test/inRange/inRange.js index f0f16154b..8eaa567cf 100644 --- a/test/inRange/inRange.js +++ b/test/inRange/inRange.js @@ -2,4 +2,4 @@ const inRange = (n, start, end = null) => { if (end && start > end) end = [start, (start = end)][0]; return end == null ? n >= 0 && n < start : n >= start && n < end; }; - module.exports = inRange \ No newline at end of file +module.exports = inRange \ No newline at end of file diff --git a/test/inRange/inRange.test.js b/test/inRange/inRange.test.js index 5107eefa1..10b2a2bec 100644 --- a/test/inRange/inRange.test.js +++ b/test/inRange/inRange.test.js @@ -2,16 +2,16 @@ const test = require('tape'); const inRange = require('./inRange.js'); test('Testing inRange', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof inRange === 'function', 'inRange is a Function'); - t.equal(inRange(3, 2, 5), true, "The given number falls within the given range"); - t.equal(inRange(3, 4), true, "The given number falls within the given range"); - t.equal(inRange(2, 3, 5), false, "The given number does not falls within the given range"); - t.equal(inRange(3, 2), false, "The given number does not falls within the given range"); - //t.deepEqual(inRange(args..), 'Expected'); - //t.equal(inRange(args..), 'Expected'); - //t.false(inRange(args..), 'Expected'); - //t.throws(inRange(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof inRange === 'function', 'inRange is a Function'); + t.equal(inRange(3, 2, 5), true, "The given number falls within the given range"); + t.equal(inRange(3, 4), true, "The given number falls within the given range"); + t.equal(inRange(2, 3, 5), false, "The given number does not falls within the given range"); + t.equal(inRange(3, 2), false, "The given number does not falls within the given range"); + //t.deepEqual(inRange(args..), 'Expected'); + //t.equal(inRange(args..), 'Expected'); + //t.false(inRange(args..), 'Expected'); + //t.throws(inRange(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/indexOfAll/indexOfAll.js b/test/indexOfAll/indexOfAll.js index 8eebcf8a4..e99be6004 100644 --- a/test/indexOfAll/indexOfAll.js +++ b/test/indexOfAll/indexOfAll.js @@ -3,4 +3,4 @@ const indices = []; arr.forEach((el, i) => el === val && indices.push(i)); return indices; }; - module.exports = indexOfAll \ No newline at end of file +module.exports = indexOfAll \ No newline at end of file diff --git a/test/indexOfAll/indexOfAll.test.js b/test/indexOfAll/indexOfAll.test.js index 9adf23302..d9c681a65 100644 --- a/test/indexOfAll/indexOfAll.test.js +++ b/test/indexOfAll/indexOfAll.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const indexOfAll = require('./indexOfAll.js'); test('Testing indexOfAll', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof indexOfAll === 'function', 'indexOfAll is a Function'); - t.deepEqual(indexOfAll([1, 2, 3, 1, 2, 3], 1), [0,3], "Returns all indices of val in an array"); - t.deepEqual(indexOfAll([1, 2, 3], 4), [], "Returns all indices of val in an array"); - //t.deepEqual(indexOfAll(args..), 'Expected'); - //t.equal(indexOfAll(args..), 'Expected'); - //t.false(indexOfAll(args..), 'Expected'); - //t.throws(indexOfAll(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof indexOfAll === 'function', 'indexOfAll is a Function'); + t.deepEqual(indexOfAll([1, 2, 3, 1, 2, 3], 1), [0,3], "Returns all indices of val in an array"); + t.deepEqual(indexOfAll([1, 2, 3], 4), [], "Returns all indices of val in an array"); + //t.deepEqual(indexOfAll(args..), 'Expected'); + //t.equal(indexOfAll(args..), 'Expected'); + //t.false(indexOfAll(args..), 'Expected'); + //t.throws(indexOfAll(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/initial/initial.js b/test/initial/initial.js index 66869d7d1..c7ed44b13 100644 --- a/test/initial/initial.js +++ b/test/initial/initial.js @@ -1,2 +1,2 @@ const initial = arr => arr.slice(0, -1); - module.exports = initial \ No newline at end of file +module.exports = initial \ No newline at end of file diff --git a/test/initial/initial.test.js b/test/initial/initial.test.js index 5b72d4bfb..d4b0b76d6 100644 --- a/test/initial/initial.test.js +++ b/test/initial/initial.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const initial = require('./initial.js'); test('Testing initial', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof initial === 'function', 'initial is a Function'); - t.deepEqual(initial([1, 2, 3]), [1, 2], "Returns all the elements of an array except the last one"); - //t.deepEqual(initial(args..), 'Expected'); - //t.equal(initial(args..), 'Expected'); - //t.false(initial(args..), 'Expected'); - //t.throws(initial(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof initial === 'function', 'initial is a Function'); + t.deepEqual(initial([1, 2, 3]), [1, 2], "Returns all the elements of an array except the last one"); + //t.deepEqual(initial(args..), 'Expected'); + //t.equal(initial(args..), 'Expected'); + //t.false(initial(args..), 'Expected'); + //t.throws(initial(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/initialize2DArray/initialize2DArray.js b/test/initialize2DArray/initialize2DArray.js index b8a85fd93..00b71e6af 100644 --- a/test/initialize2DArray/initialize2DArray.js +++ b/test/initialize2DArray/initialize2DArray.js @@ -1,3 +1,3 @@ const initialize2DArray = (w, h, val = null) => Array.from({ length: h }).map(() => Array.from({ length: w }).fill(val)); - module.exports = initialize2DArray \ No newline at end of file +module.exports = initialize2DArray \ No newline at end of file diff --git a/test/initialize2DArray/initialize2DArray.test.js b/test/initialize2DArray/initialize2DArray.test.js index 73699d3bb..d2436a46a 100644 --- a/test/initialize2DArray/initialize2DArray.test.js +++ b/test/initialize2DArray/initialize2DArray.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const initialize2DArray = require('./initialize2DArray.js'); test('Testing initialize2DArray', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof initialize2DArray === 'function', 'initialize2DArray is a Function'); - t.deepEqual(initialize2DArray(2, 2, 0), [[0,0], [0,0]], "Initializes a 2D array of given width and height and value"); - //t.deepEqual(initialize2DArray(args..), 'Expected'); - //t.equal(initialize2DArray(args..), 'Expected'); - //t.false(initialize2DArray(args..), 'Expected'); - //t.throws(initialize2DArray(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof initialize2DArray === 'function', 'initialize2DArray is a Function'); + t.deepEqual(initialize2DArray(2, 2, 0), [[0,0], [0,0]], "Initializes a 2D array of given width and height and value"); + //t.deepEqual(initialize2DArray(args..), 'Expected'); + //t.equal(initialize2DArray(args..), 'Expected'); + //t.false(initialize2DArray(args..), 'Expected'); + //t.throws(initialize2DArray(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/initializeArrayWithRange/initializeArrayWithRange.js b/test/initializeArrayWithRange/initializeArrayWithRange.js index 2b875d6b9..11132582e 100644 --- a/test/initializeArrayWithRange/initializeArrayWithRange.js +++ b/test/initializeArrayWithRange/initializeArrayWithRange.js @@ -1,3 +1,3 @@ const initializeArrayWithRange = (end, start = 0, step = 1) => Array.from({ length: Math.ceil((end + 1 - start) / step) }).map((v, i) => i * step + start); - module.exports = initializeArrayWithRange \ No newline at end of file +module.exports = initializeArrayWithRange \ No newline at end of file diff --git a/test/initializeArrayWithRange/initializeArrayWithRange.test.js b/test/initializeArrayWithRange/initializeArrayWithRange.test.js index 0d7db7b62..c35b1f557 100644 --- a/test/initializeArrayWithRange/initializeArrayWithRange.test.js +++ b/test/initializeArrayWithRange/initializeArrayWithRange.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const initializeArrayWithRange = require('./initializeArrayWithRange.js'); test('Testing initializeArrayWithRange', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof initializeArrayWithRange === 'function', 'initializeArrayWithRange is a Function'); - t.deepEqual(initializeArrayWithRange(5), [0, 1, 2, 3, 4, 5], "Initializes an array containing the numbers in the specified range"); - //t.deepEqual(initializeArrayWithRange(args..), 'Expected'); - //t.equal(initializeArrayWithRange(args..), 'Expected'); - //t.false(initializeArrayWithRange(args..), 'Expected'); - //t.throws(initializeArrayWithRange(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof initializeArrayWithRange === 'function', 'initializeArrayWithRange is a Function'); + t.deepEqual(initializeArrayWithRange(5), [0, 1, 2, 3, 4, 5], "Initializes an array containing the numbers in the specified range"); + //t.deepEqual(initializeArrayWithRange(args..), 'Expected'); + //t.equal(initializeArrayWithRange(args..), 'Expected'); + //t.false(initializeArrayWithRange(args..), 'Expected'); + //t.throws(initializeArrayWithRange(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/initializeArrayWithRangeRight/initializeArrayWithRangeRight.js b/test/initializeArrayWithRangeRight/initializeArrayWithRangeRight.js index 957361046..478a73f2c 100644 --- a/test/initializeArrayWithRangeRight/initializeArrayWithRangeRight.js +++ b/test/initializeArrayWithRangeRight/initializeArrayWithRangeRight.js @@ -2,4 +2,4 @@ const initializeArrayWithRangeRight = (end, start = 0, step = 1) => Array.from({ length: Math.ceil((end + 1 - start) / step) }).map( (v, i, arr) => (arr.length - i - 1) * step + start ); - module.exports = initializeArrayWithRangeRight \ No newline at end of file +module.exports = initializeArrayWithRangeRight \ No newline at end of file diff --git a/test/initializeArrayWithRangeRight/initializeArrayWithRangeRight.test.js b/test/initializeArrayWithRangeRight/initializeArrayWithRangeRight.test.js index 34418ca28..f630da0c4 100644 --- a/test/initializeArrayWithRangeRight/initializeArrayWithRangeRight.test.js +++ b/test/initializeArrayWithRangeRight/initializeArrayWithRangeRight.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const initializeArrayWithRangeRight = require('./initializeArrayWithRangeRight.js'); test('Testing initializeArrayWithRangeRight', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof initializeArrayWithRangeRight === 'function', 'initializeArrayWithRangeRight is a Function'); - //t.deepEqual(initializeArrayWithRangeRight(args..), 'Expected'); - //t.equal(initializeArrayWithRangeRight(args..), 'Expected'); - //t.false(initializeArrayWithRangeRight(args..), 'Expected'); - //t.throws(initializeArrayWithRangeRight(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof initializeArrayWithRangeRight === 'function', 'initializeArrayWithRangeRight is a Function'); + //t.deepEqual(initializeArrayWithRangeRight(args..), 'Expected'); + //t.equal(initializeArrayWithRangeRight(args..), 'Expected'); + //t.false(initializeArrayWithRangeRight(args..), 'Expected'); + //t.throws(initializeArrayWithRangeRight(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/initializeArrayWithValues/initializeArrayWithValues.js b/test/initializeArrayWithValues/initializeArrayWithValues.js index a9e77c805..32e55933a 100644 --- a/test/initializeArrayWithValues/initializeArrayWithValues.js +++ b/test/initializeArrayWithValues/initializeArrayWithValues.js @@ -1,2 +1,2 @@ const initializeArrayWithValues = (n, val = 0) => Array(n).fill(val); - module.exports = initializeArrayWithValues \ No newline at end of file +module.exports = initializeArrayWithValues \ No newline at end of file diff --git a/test/initializeArrayWithValues/initializeArrayWithValues.test.js b/test/initializeArrayWithValues/initializeArrayWithValues.test.js index bfbb060b1..e4590fcaa 100644 --- a/test/initializeArrayWithValues/initializeArrayWithValues.test.js +++ b/test/initializeArrayWithValues/initializeArrayWithValues.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const initializeArrayWithValues = require('./initializeArrayWithValues.js'); test('Testing initializeArrayWithValues', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof initializeArrayWithValues === 'function', 'initializeArrayWithValues is a Function'); - t.deepEqual(initializeArrayWithValues(5, 2), [2, 2, 2, 2, 2], "Initializes and fills an array with the specified values"); - //t.deepEqual(initializeArrayWithValues(args..), 'Expected'); - //t.equal(initializeArrayWithValues(args..), 'Expected'); - //t.false(initializeArrayWithValues(args..), 'Expected'); - //t.throws(initializeArrayWithValues(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof initializeArrayWithValues === 'function', 'initializeArrayWithValues is a Function'); + t.deepEqual(initializeArrayWithValues(5, 2), [2, 2, 2, 2, 2], "Initializes and fills an array with the specified values"); + //t.deepEqual(initializeArrayWithValues(args..), 'Expected'); + //t.equal(initializeArrayWithValues(args..), 'Expected'); + //t.false(initializeArrayWithValues(args..), 'Expected'); + //t.throws(initializeArrayWithValues(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/intersection/intersection.js b/test/intersection/intersection.js index b547b9136..c637ae88f 100644 --- a/test/intersection/intersection.js +++ b/test/intersection/intersection.js @@ -2,4 +2,4 @@ const intersection = (a, b) => { const s = new Set(b); return a.filter(x => s.has(x)); }; - module.exports = intersection \ No newline at end of file +module.exports = intersection \ No newline at end of file diff --git a/test/intersection/intersection.test.js b/test/intersection/intersection.test.js index 078a912c1..065d86356 100644 --- a/test/intersection/intersection.test.js +++ b/test/intersection/intersection.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const intersection = require('./intersection.js'); test('Testing intersection', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof intersection === 'function', 'intersection is a Function'); - t.deepEqual(intersection([1, 2, 3], [4, 3, 2]), [2, 3], "Returns a list of elements that exist in both arrays"); - //t.deepEqual(intersection(args..), 'Expected'); - //t.equal(intersection(args..), 'Expected'); - //t.false(intersection(args..), 'Expected'); - //t.throws(intersection(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof intersection === 'function', 'intersection is a Function'); + t.deepEqual(intersection([1, 2, 3], [4, 3, 2]), [2, 3], "Returns a list of elements that exist in both arrays"); + //t.deepEqual(intersection(args..), 'Expected'); + //t.equal(intersection(args..), 'Expected'); + //t.false(intersection(args..), 'Expected'); + //t.throws(intersection(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/intersectionBy/intersectionBy.js b/test/intersectionBy/intersectionBy.js new file mode 100644 index 000000000..78b3549c5 --- /dev/null +++ b/test/intersectionBy/intersectionBy.js @@ -0,0 +1,5 @@ +const intersectionBy = (a, b, fn) => { +const s = new Set(b.map(x => fn(x))); +return a.filter(x => s.has(fn(x))); +}; +module.exports = intersectionBy \ No newline at end of file diff --git a/test/intersectionBy/intersectionBy.test.js b/test/intersectionBy/intersectionBy.test.js new file mode 100644 index 000000000..f9cead537 --- /dev/null +++ b/test/intersectionBy/intersectionBy.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const intersectionBy = require('./intersectionBy.js'); + +test('Testing intersectionBy', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof intersectionBy === 'function', 'intersectionBy is a Function'); + //t.deepEqual(intersectionBy(args..), 'Expected'); + //t.equal(intersectionBy(args..), 'Expected'); + //t.false(intersectionBy(args..), 'Expected'); + //t.throws(intersectionBy(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/intersectionWith/intersectionWith.js b/test/intersectionWith/intersectionWith.js new file mode 100644 index 000000000..4d01fb1a9 --- /dev/null +++ b/test/intersectionWith/intersectionWith.js @@ -0,0 +1,2 @@ +const intersectionWith = (a, b, comp) => a.filter(x => b.findIndex(y => comp(x, y)) !== -1); +module.exports = intersectionWith \ No newline at end of file diff --git a/test/intersectionWith/intersectionWith.test.js b/test/intersectionWith/intersectionWith.test.js new file mode 100644 index 000000000..061a95a96 --- /dev/null +++ b/test/intersectionWith/intersectionWith.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const intersectionWith = require('./intersectionWith.js'); + +test('Testing intersectionWith', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof intersectionWith === 'function', 'intersectionWith is a Function'); + //t.deepEqual(intersectionWith(args..), 'Expected'); + //t.equal(intersectionWith(args..), 'Expected'); + //t.false(intersectionWith(args..), 'Expected'); + //t.throws(intersectionWith(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/invertKeyValues/invertKeyValues.js b/test/invertKeyValues/invertKeyValues.js index bbb96740f..0b2b5f35b 100644 --- a/test/invertKeyValues/invertKeyValues.js +++ b/test/invertKeyValues/invertKeyValues.js @@ -1,6 +1,8 @@ -const invertKeyValues = obj => +const invertKeyValues = (obj, fn) => Object.keys(obj).reduce((acc, key) => { -acc[obj[key]] = key; +const val = fn ? fn(obj[key]) : obj[key]; +acc[val] = acc[val] || []; +acc[val].push(key); return acc; }, {}); - module.exports = invertKeyValues \ No newline at end of file +module.exports = invertKeyValues \ No newline at end of file diff --git a/test/invertKeyValues/invertKeyValues.test.js b/test/invertKeyValues/invertKeyValues.test.js index 41c0a4bc0..948a80889 100644 --- a/test/invertKeyValues/invertKeyValues.test.js +++ b/test/invertKeyValues/invertKeyValues.test.js @@ -2,13 +2,14 @@ const test = require('tape'); const invertKeyValues = require('./invertKeyValues.js'); test('Testing invertKeyValues', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof invertKeyValues === 'function', 'invertKeyValues is a Function'); - t.deepEqual(invertKeyValues({ name: 'John', age: 20 }), { 20: 'age', John: 'name' }, "Inverts the key-value pairs of an object"); - //t.deepEqual(invertKeyValues(args..), 'Expected'); - //t.equal(invertKeyValues(args..), 'Expected'); - //t.false(invertKeyValues(args..), 'Expected'); - //t.throws(invertKeyValues(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof invertKeyValues === 'function', 'invertKeyValues is a Function'); + t.deepEqual(invertKeyValues({ a: 1, b: 2, c: 1 }), { 1: [ 'a', 'c' ], 2: [ 'b' ] }, "invertKeyValues({ a: 1, b: 2, c: 1 }) returns { 1: [ 'a', 'c' ], 2: [ 'b' ] }"); + t.deepEqual(invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value), { group1: [ 'a', 'c' ], group2: [ 'b' ] }, "invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value) returns { group1: [ 'a', 'c' ], group2: [ 'b' ] }"); + //t.deepEqual(invertKeyValues(args..), 'Expected'); + //t.equal(invertKeyValues(args..), 'Expected'); + //t.false(invertKeyValues(args..), 'Expected'); + //t.throws(invertKeyValues(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/is/is.js b/test/is/is.js index 829c5d16e..59035ba79 100644 --- a/test/is/is.js +++ b/test/is/is.js @@ -1,2 +1,2 @@ const is = (type, val) => val instanceof type; - module.exports = is \ No newline at end of file +module.exports = is \ No newline at end of file diff --git a/test/is/is.test.js b/test/is/is.test.js index 78d7b1e3a..d99c05d6f 100644 --- a/test/is/is.test.js +++ b/test/is/is.test.js @@ -2,12 +2,28 @@ const test = require('tape'); const is = require('./is.js'); test('Testing is', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof is === 'function', 'is is a Function'); - //t.deepEqual(is(args..), 'Expected'); - //t.equal(is(args..), 'Expected'); - //t.false(is(args..), 'Expected'); - //t.throws(is(args..), 'Expected'); - t.end(); -}); \ No newline at end of file + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof is === 'function', 'is is a Function'); + t.true(is(Array, [1]), `Works for arrays with data`); + t.true(is(Array, []), `Works for empty arrays`); + t.false(is(Array, {}), `Works for arrays, not objects`); + t.true(is(Object, {}), `Works for objects`); + t.true(is(Map, new Map()), `Works for maps`); + t.true(is(RegExp, /./g), `Works for regular expressions`); + t.true(is(Set, new Set()), `Works for sets`); + t.true(is(WeakMap, new WeakMap()), `Works for weak maps`); + t.true(is(WeakSet, new WeakSet()), `Works for weak sets`); + t.false(is(String, ''), `Works for strings - returns false for primitive`); + t.true(is(String, new String('')), `Works for strings - returns true when using constructor`); + t.false(is(Number, 1), `Works for numbers - returns false for primitive`); + t.true(is(Number, new Number('10')), `Works for numbers - returns true when using constructor`); + t.false(is(Boolean, false), `Works for booleans - returns false for primitive`); + t.true(is(Boolean, new Boolean(false)), `Works for booleans - returns true when using constructor`); + t.true(is(Function, () => null), `Works for functions`); + //t.deepEqual(is(args..), 'Expected'); + //t.equal(is(args..), 'Expected'); + //t.false(is(args..), 'Expected'); + //t.throws(is(args..), 'Expected'); + t.end(); +}); diff --git a/test/isAbsoluteURL/isAbsoluteURL.js b/test/isAbsoluteURL/isAbsoluteURL.js index fcfb3e490..31accb72d 100644 --- a/test/isAbsoluteURL/isAbsoluteURL.js +++ b/test/isAbsoluteURL/isAbsoluteURL.js @@ -1,2 +1,2 @@ const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str); - module.exports = isAbsoluteURL \ No newline at end of file +module.exports = isAbsoluteURL \ No newline at end of file diff --git a/test/isAbsoluteURL/isAbsoluteURL.test.js b/test/isAbsoluteURL/isAbsoluteURL.test.js index 31ede0273..965d48cdc 100644 --- a/test/isAbsoluteURL/isAbsoluteURL.test.js +++ b/test/isAbsoluteURL/isAbsoluteURL.test.js @@ -2,15 +2,15 @@ const test = require('tape'); const isAbsoluteURL = require('./isAbsoluteURL.js'); test('Testing isAbsoluteURL', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isAbsoluteURL === 'function', 'isAbsoluteURL is a Function'); - t.equal(isAbsoluteURL('https://google.com'), true, "Given string is an absolute URL"); - t.equal(isAbsoluteURL('ftp://www.myserver.net'), true, "Given string is an absolute URL"); - t.equal(isAbsoluteURL('/foo/bar'), false, "Given string is not an absolute URL"); - //t.deepEqual(isAbsoluteURL(args..), 'Expected'); - //t.equal(isAbsoluteURL(args..), 'Expected'); - //t.false(isAbsoluteURL(args..), 'Expected'); - //t.throws(isAbsoluteURL(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isAbsoluteURL === 'function', 'isAbsoluteURL is a Function'); + t.equal(isAbsoluteURL('https://google.com'), true, "Given string is an absolute URL"); + t.equal(isAbsoluteURL('ftp://www.myserver.net'), true, "Given string is an absolute URL"); + t.equal(isAbsoluteURL('/foo/bar'), false, "Given string is not an absolute URL"); + //t.deepEqual(isAbsoluteURL(args..), 'Expected'); + //t.equal(isAbsoluteURL(args..), 'Expected'); + //t.false(isAbsoluteURL(args..), 'Expected'); + //t.throws(isAbsoluteURL(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isArmstrongNumber/isArmstrongNumber.js b/test/isArmstrongNumber/isArmstrongNumber.js index dbbb3bc7f..e71055d5d 100644 --- a/test/isArmstrongNumber/isArmstrongNumber.js +++ b/test/isArmstrongNumber/isArmstrongNumber.js @@ -2,4 +2,4 @@ const isArmstrongNumber = digits => (arr => arr.reduce((a, d) => a + parseInt(d) ** arr.length, 0) == digits)( (digits + '').split('') ); - module.exports = isArmstrongNumber \ No newline at end of file +module.exports = isArmstrongNumber \ No newline at end of file diff --git a/test/isArmstrongNumber/isArmstrongNumber.test.js b/test/isArmstrongNumber/isArmstrongNumber.test.js index d3e32e507..dbebfbfd0 100644 --- a/test/isArmstrongNumber/isArmstrongNumber.test.js +++ b/test/isArmstrongNumber/isArmstrongNumber.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const isArmstrongNumber = require('./isArmstrongNumber.js'); test('Testing isArmstrongNumber', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isArmstrongNumber === 'function', 'isArmstrongNumber is a Function'); - //t.deepEqual(isArmstrongNumber(args..), 'Expected'); - //t.equal(isArmstrongNumber(args..), 'Expected'); - //t.false(isArmstrongNumber(args..), 'Expected'); - //t.throws(isArmstrongNumber(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isArmstrongNumber === 'function', 'isArmstrongNumber is a Function'); + //t.deepEqual(isArmstrongNumber(args..), 'Expected'); + //t.equal(isArmstrongNumber(args..), 'Expected'); + //t.false(isArmstrongNumber(args..), 'Expected'); + //t.throws(isArmstrongNumber(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isArray/isArray.test.js b/test/isArray/isArray.test.js index 26c1dc5c0..7d56d1112 100644 --- a/test/isArray/isArray.test.js +++ b/test/isArray/isArray.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const isArray = require('./isArray.js'); test('Testing isArray', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isArray === 'function', 'isArray is a Function'); - t.equal(isArray([1]), true, "passed value is an array"); - t.equal(isArray('array'), false, "passed value is not an array"); - //t.equal(isArray(args..), 'Expected'); - //t.false(isArray(args..), 'Expected'); - //t.throws(isArray(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isArray === 'function', 'isArray is a Function'); + t.equal(isArray([1]), true, "passed value is an array"); + t.equal(isArray('array'), false, "passed value is not an array"); + //t.equal(isArray(args..), 'Expected'); + //t.false(isArray(args..), 'Expected'); + //t.throws(isArray(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isArrayBuffer/isArrayBuffer.test.js b/test/isArrayBuffer/isArrayBuffer.test.js index 8b3656960..1d9cffa97 100644 --- a/test/isArrayBuffer/isArrayBuffer.test.js +++ b/test/isArrayBuffer/isArrayBuffer.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const isArrayBuffer = require('./isArrayBuffer.js'); test('Testing isArrayBuffer', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isArrayBuffer === 'function', 'isArrayBuffer is a Function'); - //t.deepEqual(isArrayBuffer(args..), 'Expected'); - //t.equal(isArrayBuffer(args..), 'Expected'); - //t.false(isArrayBuffer(args..), 'Expected'); - //t.throws(isArrayBuffer(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isArrayBuffer === 'function', 'isArrayBuffer is a Function'); + //t.deepEqual(isArrayBuffer(args..), 'Expected'); + //t.equal(isArrayBuffer(args..), 'Expected'); + //t.false(isArrayBuffer(args..), 'Expected'); + //t.throws(isArrayBuffer(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isArrayLike/isArrayLike.js b/test/isArrayLike/isArrayLike.js index ce5a35eb5..4930908ec 100644 --- a/test/isArrayLike/isArrayLike.js +++ b/test/isArrayLike/isArrayLike.js @@ -5,4 +5,4 @@ return [...val], true; return false; } }; - module.exports = isArrayLike \ No newline at end of file +module.exports = isArrayLike \ No newline at end of file diff --git a/test/isArrayLike/isArrayLike.test.js b/test/isArrayLike/isArrayLike.test.js index d8a528c05..2239caf3d 100644 --- a/test/isArrayLike/isArrayLike.test.js +++ b/test/isArrayLike/isArrayLike.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const isArrayLike = require('./isArrayLike.js'); test('Testing isArrayLike', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isArrayLike === 'function', 'isArrayLike is a Function'); - //t.deepEqual(isArrayLike(args..), 'Expected'); - //t.equal(isArrayLike(args..), 'Expected'); - //t.false(isArrayLike(args..), 'Expected'); - //t.throws(isArrayLike(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isArrayLike === 'function', 'isArrayLike is a Function'); + //t.deepEqual(isArrayLike(args..), 'Expected'); + //t.equal(isArrayLike(args..), 'Expected'); + //t.false(isArrayLike(args..), 'Expected'); + //t.throws(isArrayLike(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isBoolean/isBoolean.js b/test/isBoolean/isBoolean.js index 96d35cc5b..1ae8e4c9c 100644 --- a/test/isBoolean/isBoolean.js +++ b/test/isBoolean/isBoolean.js @@ -1,2 +1,2 @@ const isBoolean = val => typeof val === 'boolean'; - module.exports = isBoolean \ No newline at end of file +module.exports = isBoolean \ No newline at end of file diff --git a/test/isBoolean/isBoolean.test.js b/test/isBoolean/isBoolean.test.js index c18f04d02..68334e925 100644 --- a/test/isBoolean/isBoolean.test.js +++ b/test/isBoolean/isBoolean.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const isBoolean = require('./isBoolean.js'); test('Testing isBoolean', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isBoolean === 'function', 'isBoolean is a Function'); - t.equal(isBoolean(null), false, "passed value is not a boolean"); - t.equal(isBoolean(false), true, "passed value is not a boolean"); - //t.deepEqual(isBoolean(args..), 'Expected'); - //t.equal(isBoolean(args..), 'Expected'); - //t.false(isBoolean(args..), 'Expected'); - //t.throws(isBoolean(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isBoolean === 'function', 'isBoolean is a Function'); + t.equal(isBoolean(null), false, "passed value is not a boolean"); + t.equal(isBoolean(false), true, "passed value is not a boolean"); + //t.deepEqual(isBoolean(args..), 'Expected'); + //t.equal(isBoolean(args..), 'Expected'); + //t.false(isBoolean(args..), 'Expected'); + //t.throws(isBoolean(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isDivisible/isDivisible.js b/test/isDivisible/isDivisible.js index cb4cf5ace..a0f9d226d 100644 --- a/test/isDivisible/isDivisible.js +++ b/test/isDivisible/isDivisible.js @@ -1,2 +1,2 @@ const isDivisible = (dividend, divisor) => dividend % divisor === 0; - module.exports = isDivisible \ No newline at end of file +module.exports = isDivisible \ No newline at end of file diff --git a/test/isDivisible/isDivisible.test.js b/test/isDivisible/isDivisible.test.js index 40eeb4bc9..bdfa8a5c2 100644 --- a/test/isDivisible/isDivisible.test.js +++ b/test/isDivisible/isDivisible.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const isDivisible = require('./isDivisible.js'); test('Testing isDivisible', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isDivisible === 'function', 'isDivisible is a Function'); - t.equal(isDivisible(6, 3), true, 'The number 6 is divisible by 3'); - //t.deepEqual(isDivisible(args..), 'Expected'); - //t.false(isDivisible(args..), 'Expected'); - //t.throws(isDivisible(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isDivisible === 'function', 'isDivisible is a Function'); + t.equal(isDivisible(6, 3), true, 'The number 6 is divisible by 3'); + //t.deepEqual(isDivisible(args..), 'Expected'); + //t.false(isDivisible(args..), 'Expected'); + //t.throws(isDivisible(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isEmpty/isEmpty.js b/test/isEmpty/isEmpty.js new file mode 100644 index 000000000..189bdf0fd --- /dev/null +++ b/test/isEmpty/isEmpty.js @@ -0,0 +1,2 @@ +const isEmpty = val => val == null || !(Object.keys(val) || val).length; +module.exports = isEmpty \ No newline at end of file diff --git a/test/isEmpty/isEmpty.test.js b/test/isEmpty/isEmpty.test.js new file mode 100644 index 000000000..2c101b5c5 --- /dev/null +++ b/test/isEmpty/isEmpty.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const isEmpty = require('./isEmpty.js'); + +test('Testing isEmpty', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isEmpty === 'function', 'isEmpty is a Function'); + //t.deepEqual(isEmpty(args..), 'Expected'); + //t.equal(isEmpty(args..), 'Expected'); + //t.false(isEmpty(args..), 'Expected'); + //t.throws(isEmpty(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/isEven/isEven.js b/test/isEven/isEven.js index 255ea706e..6807815ad 100644 --- a/test/isEven/isEven.js +++ b/test/isEven/isEven.js @@ -1,2 +1,2 @@ const isEven = num => num % 2 === 0; - module.exports = isEven \ No newline at end of file +module.exports = isEven \ No newline at end of file diff --git a/test/isEven/isEven.test.js b/test/isEven/isEven.test.js index 6436226b4..8c9e29455 100644 --- a/test/isEven/isEven.test.js +++ b/test/isEven/isEven.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const isEven = require('./isEven.js'); test('Testing isEven', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isEven === 'function', 'isEven is a Function'); - t.equal(isEven(4), true, '4 is even number'); - t.false(isEven(5), false, '5 is not an even number'); - //t.deepEqual(isEven(args..), 'Expected'); - //t.throws(isEven(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isEven === 'function', 'isEven is a Function'); + t.equal(isEven(4), true, '4 is even number'); + t.false(isEven(5), false, '5 is not an even number'); + //t.deepEqual(isEven(args..), 'Expected'); + //t.throws(isEven(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isFunction/isFunction.js b/test/isFunction/isFunction.js index c7879e596..2afc19f96 100644 --- a/test/isFunction/isFunction.js +++ b/test/isFunction/isFunction.js @@ -1,2 +1,2 @@ const isFunction = val => typeof val === 'function'; - module.exports = isFunction \ No newline at end of file +module.exports = isFunction \ No newline at end of file diff --git a/test/isFunction/isFunction.test.js b/test/isFunction/isFunction.test.js index 90ee51c8c..7311b25d4 100644 --- a/test/isFunction/isFunction.test.js +++ b/test/isFunction/isFunction.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const isFunction = require('./isFunction.js'); test('Testing isFunction', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isFunction === 'function', 'isFunction is a Function'); - t.equal(isFunction(x => x), true, "passed value is a function"); - t.equal(isFunction('x'), false, "passed value is not a function"); - //t.equal(isFunction(args..), 'Expected'); - //t.false(isFunction(args..), 'Expected'); - //t.throws(isFunction(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isFunction === 'function', 'isFunction is a Function'); + t.equal(isFunction(x => x), true, "passed value is a function"); + t.equal(isFunction('x'), false, "passed value is not a function"); + //t.equal(isFunction(args..), 'Expected'); + //t.false(isFunction(args..), 'Expected'); + //t.throws(isFunction(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isLowerCase/isLowerCase.js b/test/isLowerCase/isLowerCase.js index 2eb3496a3..b717cbc36 100644 --- a/test/isLowerCase/isLowerCase.js +++ b/test/isLowerCase/isLowerCase.js @@ -1,2 +1,2 @@ const isLowerCase = str => str === str.toLowerCase(); - module.exports = isLowerCase \ No newline at end of file +module.exports = isLowerCase \ No newline at end of file diff --git a/test/isLowerCase/isLowerCase.test.js b/test/isLowerCase/isLowerCase.test.js index 815babfe4..0e596dff9 100644 --- a/test/isLowerCase/isLowerCase.test.js +++ b/test/isLowerCase/isLowerCase.test.js @@ -2,15 +2,15 @@ const test = require('tape'); const isLowerCase = require('./isLowerCase.js'); test('Testing isLowerCase', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isLowerCase === 'function', 'isLowerCase is a Function'); - t.equal(isLowerCase('abc'), true, "passed string is a lowercase"); - t.equal(isLowerCase('a3@$'), true, "passed string is a lowercase"); - t.equal(isLowerCase('A3@$'), false, "passed value is not a lowercase"); - //t.deepEqual(isLowerCase(args..), 'Expected'); - //t.equal(isLowerCase(args..), 'Expected'); - //t.false(isLowerCase(args..), 'Expected'); - //t.throws(isLowerCase(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isLowerCase === 'function', 'isLowerCase is a Function'); + t.equal(isLowerCase('abc'), true, "passed string is a lowercase"); + t.equal(isLowerCase('a3@$'), true, "passed string is a lowercase"); + t.equal(isLowerCase('A3@$'), false, "passed value is not a lowercase"); + //t.deepEqual(isLowerCase(args..), 'Expected'); + //t.equal(isLowerCase(args..), 'Expected'); + //t.false(isLowerCase(args..), 'Expected'); + //t.throws(isLowerCase(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isMap/isMap.test.js b/test/isMap/isMap.test.js index 4f73f16de..bc9fe3187 100644 --- a/test/isMap/isMap.test.js +++ b/test/isMap/isMap.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const isMap = require('./isMap.js'); test('Testing isMap', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isMap === 'function', 'isMap is a Function'); - //t.deepEqual(isMap(args..), 'Expected'); - //t.equal(isMap(args..), 'Expected'); - //t.false(isMap(args..), 'Expected'); - //t.throws(isMap(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isMap === 'function', 'isMap is a Function'); + //t.deepEqual(isMap(args..), 'Expected'); + //t.equal(isMap(args..), 'Expected'); + //t.false(isMap(args..), 'Expected'); + //t.throws(isMap(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isNil/isNil.js b/test/isNil/isNil.js index f7a372152..aed4ee641 100644 --- a/test/isNil/isNil.js +++ b/test/isNil/isNil.js @@ -1,2 +1,2 @@ const isNil = val => val === undefined || val === null; - module.exports = isNil \ No newline at end of file +module.exports = isNil \ No newline at end of file diff --git a/test/isNil/isNil.test.js b/test/isNil/isNil.test.js index 324d68b84..4ad388e23 100644 --- a/test/isNil/isNil.test.js +++ b/test/isNil/isNil.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const isNil = require('./isNil.js'); test('Testing isNil', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isNil === 'function', 'isNil is a Function'); - //t.deepEqual(isNil(args..), 'Expected'); - //t.equal(isNil(args..), 'Expected'); - //t.false(isNil(args..), 'Expected'); - //t.throws(isNil(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isNil === 'function', 'isNil is a Function'); + //t.deepEqual(isNil(args..), 'Expected'); + //t.equal(isNil(args..), 'Expected'); + //t.false(isNil(args..), 'Expected'); + //t.throws(isNil(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isNull/isNull.js b/test/isNull/isNull.js index 89d25db2d..a741e6a67 100644 --- a/test/isNull/isNull.js +++ b/test/isNull/isNull.js @@ -1,2 +1,2 @@ const isNull = val => val === null; - module.exports = isNull \ No newline at end of file +module.exports = isNull \ No newline at end of file diff --git a/test/isNull/isNull.test.js b/test/isNull/isNull.test.js index 4244872b0..dbc7d20c8 100644 --- a/test/isNull/isNull.test.js +++ b/test/isNull/isNull.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const isNull = require('./isNull.js'); test('Testing isNull', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isNull === 'function', 'isNull is a Function'); - t.equal(isNull(null), true, "passed argument is a null"); - t.equal(isNull(NaN), false, "passed argument is a null"); - //t.deepEqual(isNull(args..), 'Expected'); - //t.equal(isNull(args..), 'Expected'); - //t.false(isNull(args..), 'Expected'); - //t.throws(isNull(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isNull === 'function', 'isNull is a Function'); + t.equal(isNull(null), true, "passed argument is a null"); + t.equal(isNull(NaN), false, "passed argument is a null"); + //t.deepEqual(isNull(args..), 'Expected'); + //t.equal(isNull(args..), 'Expected'); + //t.false(isNull(args..), 'Expected'); + //t.throws(isNull(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isNumber/isNumber.js b/test/isNumber/isNumber.js index 49ada847c..89c9390bf 100644 --- a/test/isNumber/isNumber.js +++ b/test/isNumber/isNumber.js @@ -1,2 +1,2 @@ const isNumber = val => typeof val === 'number'; - module.exports = isNumber \ No newline at end of file +module.exports = isNumber \ No newline at end of file diff --git a/test/isNumber/isNumber.test.js b/test/isNumber/isNumber.test.js index 3845c0818..90af5bb5b 100644 --- a/test/isNumber/isNumber.test.js +++ b/test/isNumber/isNumber.test.js @@ -2,15 +2,15 @@ const test = require('tape'); const isNumber = require('./isNumber.js'); test('Testing isNumber', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isNumber === 'function', 'isNumber is a Function'); - t.equal(isNumber(1), true, "passed argument is a number"); - t.equal(isNumber('1'), false, "passed argument is not a number"); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isNumber === 'function', 'isNumber is a Function'); + t.equal(isNumber(1), true, "passed argument is a number"); + t.equal(isNumber('1'), false, "passed argument is not a number"); - //t.deepEqual(isNumber(args..), 'Expected'); - //t.equal(isNumber(args..), 'Expected'); - //t.false(isNumber(args..), 'Expected'); - //t.throws(isNumber(args..), 'Expected'); - t.end(); + //t.deepEqual(isNumber(args..), 'Expected'); + //t.equal(isNumber(args..), 'Expected'); + //t.false(isNumber(args..), 'Expected'); + //t.throws(isNumber(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isObject/isObject.js b/test/isObject/isObject.js index e6b532d48..087cedddd 100644 --- a/test/isObject/isObject.js +++ b/test/isObject/isObject.js @@ -1,2 +1,2 @@ const isObject = obj => obj === Object(obj); - module.exports = isObject \ No newline at end of file +module.exports = isObject \ No newline at end of file diff --git a/test/isObject/isObject.test.js b/test/isObject/isObject.test.js index b9a2e77b1..8ed7620c8 100644 --- a/test/isObject/isObject.test.js +++ b/test/isObject/isObject.test.js @@ -2,18 +2,18 @@ const test = require('tape'); const isObject = require('./isObject.js'); test('Testing isObject', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isObject === 'function', 'isObject is a Function'); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isObject === 'function', 'isObject is a Function'); - t.true(isObject([1, 2, 3, 4]), 'isObject([1, 2, 3, 4]) is a object'); - t.true(isObject([]), 'isObject([]) is a object'); - t.true(isObject({ a:1 }), 'isObject({ a:1 }) is a object'); - t.false(isObject(true), 'isObject(true) is not a object'); + t.true(isObject([1, 2, 3, 4]), 'isObject([1, 2, 3, 4]) is a object'); + t.true(isObject([]), 'isObject([]) is a object'); + t.true(isObject({ a:1 }), 'isObject({ a:1 }) is a object'); + t.false(isObject(true), 'isObject(true) is not a object'); - //t.deepEqual(isObject(args..), 'Expected'); - //t.equal(isObject(args..), 'Expected'); - //t.false(isObject(args..), 'Expected'); - //t.throws(isObject(args..), 'Expected'); - t.end(); + //t.deepEqual(isObject(args..), 'Expected'); + //t.equal(isObject(args..), 'Expected'); + //t.false(isObject(args..), 'Expected'); + //t.throws(isObject(args..), 'Expected'); + t.end(); }); diff --git a/test/isObjectLike/isObjectLike.js b/test/isObjectLike/isObjectLike.js new file mode 100644 index 000000000..c7088e7ad --- /dev/null +++ b/test/isObjectLike/isObjectLike.js @@ -0,0 +1,2 @@ +const isObjectLike = val => val !== null && typeof val === 'object'; +module.exports = isObjectLike \ No newline at end of file diff --git a/test/isObjectLike/isObjectLike.test.js b/test/isObjectLike/isObjectLike.test.js new file mode 100644 index 000000000..aa9f7b7e8 --- /dev/null +++ b/test/isObjectLike/isObjectLike.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const isObjectLike = require('./isObjectLike.js'); + +test('Testing isObjectLike', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isObjectLike === 'function', 'isObjectLike is a Function'); + //t.deepEqual(isObjectLike(args..), 'Expected'); + //t.equal(isObjectLike(args..), 'Expected'); + //t.false(isObjectLike(args..), 'Expected'); + //t.throws(isObjectLike(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/isPlainObject/isPlainObject.js b/test/isPlainObject/isPlainObject.js new file mode 100644 index 000000000..3e85aaf92 --- /dev/null +++ b/test/isPlainObject/isPlainObject.js @@ -0,0 +1,2 @@ +const isPlainObject = val => !!val && typeof val === 'object' && val.constructor === Object; +module.exports = isPlainObject \ No newline at end of file diff --git a/test/isPlainObject/isPlainObject.test.js b/test/isPlainObject/isPlainObject.test.js new file mode 100644 index 000000000..9de8feba3 --- /dev/null +++ b/test/isPlainObject/isPlainObject.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const isPlainObject = require('./isPlainObject.js'); + +test('Testing isPlainObject', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isPlainObject === 'function', 'isPlainObject is a Function'); + //t.deepEqual(isPlainObject(args..), 'Expected'); + //t.equal(isPlainObject(args..), 'Expected'); + //t.false(isPlainObject(args..), 'Expected'); + //t.throws(isPlainObject(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/isPrime/isPrime.js b/test/isPrime/isPrime.js index 227aae1d4..3691324d3 100644 --- a/test/isPrime/isPrime.js +++ b/test/isPrime/isPrime.js @@ -3,4 +3,4 @@ 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 \ No newline at end of file +module.exports = isPrime \ No newline at end of file diff --git a/test/isPrime/isPrime.test.js b/test/isPrime/isPrime.test.js index 7d0fdda19..8d7ce3b8b 100644 --- a/test/isPrime/isPrime.test.js +++ b/test/isPrime/isPrime.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const isPrime = require('./isPrime.js'); test('Testing isPrime', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isPrime === 'function', 'isPrime is a Function'); - t.equal(isPrime(11), true, "passed number is a prime"); - //t.deepEqual(isPrime(args..), 'Expected'); - //t.equal(isPrime(args..), 'Expected'); - //t.false(isPrime(args..), 'Expected'); - //t.throws(isPrime(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isPrime === 'function', 'isPrime is a Function'); + t.equal(isPrime(11), true, "passed number is a prime"); + //t.deepEqual(isPrime(args..), 'Expected'); + //t.equal(isPrime(args..), 'Expected'); + //t.false(isPrime(args..), 'Expected'); + //t.throws(isPrime(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isPrimitive/isPrimitive.js b/test/isPrimitive/isPrimitive.js index 45a2bc136..46c9a0568 100644 --- a/test/isPrimitive/isPrimitive.js +++ b/test/isPrimitive/isPrimitive.js @@ -1,2 +1,2 @@ const isPrimitive = val => !['object', 'function'].includes(typeof val) || val === null; - module.exports = isPrimitive \ No newline at end of file +module.exports = isPrimitive \ No newline at end of file diff --git a/test/isPrimitive/isPrimitive.test.js b/test/isPrimitive/isPrimitive.test.js index 2cebc77ff..3e0a21076 100644 --- a/test/isPrimitive/isPrimitive.test.js +++ b/test/isPrimitive/isPrimitive.test.js @@ -2,23 +2,23 @@ const test = require('tape'); const isPrimitive = require('./isPrimitive.js'); test('Testing isPrimitive', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isPrimitive === 'function', 'isPrimitive is a Function'); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isPrimitive === 'function', 'isPrimitive is a Function'); t.true(isPrimitive(null), "isPrimitive(null) is primitive"); t.true(isPrimitive(undefined), "isPrimitive(undefined) is primitive"); t.true(isPrimitive('string'), "isPrimitive(string) is primitive"); - t.true(isPrimitive(true), "isPrimitive(true) is primitive"); - t.true(isPrimitive(50), "isPrimitive(50) is primitive"); - t.true(isPrimitive('Hello'), "isPrimitive('Hello') is primitive"); - t.true(isPrimitive(false), "isPrimitive(false) is primitive"); - t.true(isPrimitive(Symbol()), "isPrimitive(Symbol()) is primitive"); - t.false(isPrimitive([1, 2, 3]), "isPrimitive([1, 2, 3]) is not primitive"); + t.true(isPrimitive(true), "isPrimitive(true) is primitive"); + t.true(isPrimitive(50), "isPrimitive(50) is primitive"); + t.true(isPrimitive('Hello'), "isPrimitive('Hello') is primitive"); + t.true(isPrimitive(false), "isPrimitive(false) is primitive"); + t.true(isPrimitive(Symbol()), "isPrimitive(Symbol()) is primitive"); + t.false(isPrimitive([1, 2, 3]), "isPrimitive([1, 2, 3]) is not primitive"); t.false(isPrimitive({ a: 123 }), "isPrimitive({ a: 123 }) is not primitive"); let start = new Date().getTime(); isPrimitive({ a: 123 }); let end = new Date().getTime(); t.true((end - start) < 2000, 'isPrimitive({ a: 123 }) takes less than 2s to run'); - t.end(); + t.end(); }); \ No newline at end of file diff --git a/test/isPromiseLike/isPromiseLike.js b/test/isPromiseLike/isPromiseLike.js index a25cb7b37..736b6ced9 100644 --- a/test/isPromiseLike/isPromiseLike.js +++ b/test/isPromiseLike/isPromiseLike.js @@ -2,4 +2,4 @@ const isPromiseLike = obj => obj !== null && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; - module.exports = isPromiseLike \ No newline at end of file +module.exports = isPromiseLike \ No newline at end of file diff --git a/test/isPromiseLike/isPromiseLike.test.js b/test/isPromiseLike/isPromiseLike.test.js index 2a8234343..b84a7c798 100644 --- a/test/isPromiseLike/isPromiseLike.test.js +++ b/test/isPromiseLike/isPromiseLike.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const isPromiseLike = require('./isPromiseLike.js'); test('Testing isPromiseLike', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isPromiseLike === 'function', 'isPromiseLike is a Function'); - //t.deepEqual(isPromiseLike(args..), 'Expected'); - //t.equal(isPromiseLike(args..), 'Expected'); - //t.false(isPromiseLike(args..), 'Expected'); - //t.throws(isPromiseLike(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isPromiseLike === 'function', 'isPromiseLike is a Function'); + //t.deepEqual(isPromiseLike(args..), 'Expected'); + //t.equal(isPromiseLike(args..), 'Expected'); + //t.false(isPromiseLike(args..), 'Expected'); + //t.throws(isPromiseLike(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isRegExp/isRegExp.test.js b/test/isRegExp/isRegExp.test.js index f896a6a62..2580a138d 100644 --- a/test/isRegExp/isRegExp.test.js +++ b/test/isRegExp/isRegExp.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const isRegExp = require('./isRegExp.js'); test('Testing isRegExp', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isRegExp === 'function', 'isRegExp is a Function'); - //t.deepEqual(isRegExp(args..), 'Expected'); - //t.equal(isRegExp(args..), 'Expected'); - //t.false(isRegExp(args..), 'Expected'); - //t.throws(isRegExp(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isRegExp === 'function', 'isRegExp is a Function'); + //t.deepEqual(isRegExp(args..), 'Expected'); + //t.equal(isRegExp(args..), 'Expected'); + //t.false(isRegExp(args..), 'Expected'); + //t.throws(isRegExp(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isSet/isSet.test.js b/test/isSet/isSet.test.js index 757064687..81fae132b 100644 --- a/test/isSet/isSet.test.js +++ b/test/isSet/isSet.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const isSet = require('./isSet.js'); test('Testing isSet', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isSet === 'function', 'isSet is a Function'); - //t.deepEqual(isSet(args..), 'Expected'); - //t.equal(isSet(args..), 'Expected'); - //t.false(isSet(args..), 'Expected'); - //t.throws(isSet(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isSet === 'function', 'isSet is a Function'); + //t.deepEqual(isSet(args..), 'Expected'); + //t.equal(isSet(args..), 'Expected'); + //t.false(isSet(args..), 'Expected'); + //t.throws(isSet(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isSorted/isSorted.js b/test/isSorted/isSorted.js index 51f645c54..c80495eb6 100644 --- a/test/isSorted/isSorted.js +++ b/test/isSorted/isSorted.js @@ -4,4 +4,4 @@ for (let [i, val] of arr.entries()) if (i === arr.length - 1) return direction; else if ((val - arr[i + 1]) * direction > 0) return 0; }; - module.exports = isSorted \ No newline at end of file +module.exports = isSorted \ No newline at end of file diff --git a/test/isSorted/isSorted.test.js b/test/isSorted/isSorted.test.js index 183435cd4..9d80c6c8e 100644 --- a/test/isSorted/isSorted.test.js +++ b/test/isSorted/isSorted.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const isSorted = require('./isSorted.js'); test('Testing isSorted', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isSorted === 'function', 'isSorted is a Function'); - //t.deepEqual(isSorted(args..), 'Expected'); - t.equal(isSorted([0, 1, 2, 2]), 1, 'Array is sorted in ascending order'); - t.equal(isSorted([4, 3, 2]), -1, 'Array is sorted in descending order'); - t.equal(isSorted([4, 3, 5]), 0, 'Array is not sorted, direction changed in array') - //t.false(isSorted(args..), 'Expected'); - //t.throws(isSorted(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isSorted === 'function', 'isSorted is a Function'); + //t.deepEqual(isSorted(args..), 'Expected'); + t.equal(isSorted([0, 1, 2, 2]), 1, 'Array is sorted in ascending order'); + t.equal(isSorted([4, 3, 2]), -1, 'Array is sorted in descending order'); + t.equal(isSorted([4, 3, 5]), 0, 'Array is not sorted, direction changed in array') + //t.false(isSorted(args..), 'Expected'); + //t.throws(isSorted(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isString/isString.js b/test/isString/isString.js index 4d866cf60..2ca94c27d 100644 --- a/test/isString/isString.js +++ b/test/isString/isString.js @@ -1,2 +1,2 @@ const isString = val => typeof val === 'string'; - module.exports = isString \ No newline at end of file +module.exports = isString \ No newline at end of file diff --git a/test/isString/isString.test.js b/test/isString/isString.test.js index 7d47db410..f48d8cfe0 100644 --- a/test/isString/isString.test.js +++ b/test/isString/isString.test.js @@ -2,18 +2,18 @@ const test = require('tape'); const isString = require('./isString.js'); test('Testing isString', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isString === 'function', 'isString is a Function'); - t.equal(isString('foo'), true, 'foo is a string'); - t.equal(isString('10'), true, '"10" is a string'); - t.equal(isString(''), true, 'Empty string is a string'); - t.equal(isString(10), false, '10 is not a string'); - t.equal(isString(true), false, 'true is not string'); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isString === 'function', 'isString is a Function'); + t.equal(isString('foo'), true, 'foo is a string'); + t.equal(isString('10'), true, '"10" is a string'); + t.equal(isString(''), true, 'Empty string is a string'); + t.equal(isString(10), false, '10 is not a string'); + t.equal(isString(true), false, 'true is not string'); - //t.deepEqual(isString(args..), 'Expected'); - //t.equal(isString(args..), 'Expected'); - //t.false(isString(args..), 'Expected'); - //t.throws(isString(args..), 'Expected'); - t.end(); + //t.deepEqual(isString(args..), 'Expected'); + //t.equal(isString(args..), 'Expected'); + //t.false(isString(args..), 'Expected'); + //t.throws(isString(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isSymbol/isSymbol.js b/test/isSymbol/isSymbol.js index cf18ba27d..f9956e85b 100644 --- a/test/isSymbol/isSymbol.js +++ b/test/isSymbol/isSymbol.js @@ -1,2 +1,2 @@ const isSymbol = val => typeof val === 'symbol'; - module.exports = isSymbol \ No newline at end of file +module.exports = isSymbol \ No newline at end of file diff --git a/test/isSymbol/isSymbol.test.js b/test/isSymbol/isSymbol.test.js index 7b7a2876b..24a4defdf 100644 --- a/test/isSymbol/isSymbol.test.js +++ b/test/isSymbol/isSymbol.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const isSymbol = require('./isSymbol.js'); test('Testing isSymbol', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isSymbol === 'function', 'isSymbol is a Function'); - t.equal(isSymbol(Symbol('x')), true, "Checks if the given argument is a symbol"); - //t.deepEqual(isSymbol(args..), 'Expected'); - //t.equal(isSymbol(args..), 'Expected'); - //t.false(isSymbol(args..), 'Expected'); - //t.throws(isSymbol(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isSymbol === 'function', 'isSymbol is a Function'); + t.equal(isSymbol(Symbol('x')), true, "Checks if the given argument is a symbol"); + //t.deepEqual(isSymbol(args..), 'Expected'); + //t.equal(isSymbol(args..), 'Expected'); + //t.false(isSymbol(args..), 'Expected'); + //t.throws(isSymbol(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isTravisCI/isTravisCI.js b/test/isTravisCI/isTravisCI.js index 19a9125c6..9dcc7e8c3 100644 --- a/test/isTravisCI/isTravisCI.js +++ b/test/isTravisCI/isTravisCI.js @@ -1,2 +1,2 @@ const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env; - module.exports = isTravisCI \ No newline at end of file +module.exports = isTravisCI \ No newline at end of file diff --git a/test/isTravisCI/isTravisCI.test.js b/test/isTravisCI/isTravisCI.test.js index e6278bcaf..603bffd6f 100644 --- a/test/isTravisCI/isTravisCI.test.js +++ b/test/isTravisCI/isTravisCI.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const isTravisCI = require('./isTravisCI.js'); test('Testing isTravisCI', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isTravisCI === 'function', 'isTravisCI is a Function'); - //t.deepEqual(isTravisCI(args..), 'Expected'); - //t.equal(isTravisCI(args..), 'Expected'); - //t.false(isTravisCI(args..), 'Expected'); - //t.throws(isTravisCI(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isTravisCI === 'function', 'isTravisCI is a Function'); + //t.deepEqual(isTravisCI(args..), 'Expected'); + //t.equal(isTravisCI(args..), 'Expected'); + //t.false(isTravisCI(args..), 'Expected'); + //t.throws(isTravisCI(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isTypedArray/isTypedArray.test.js b/test/isTypedArray/isTypedArray.test.js index abe111200..75253822d 100644 --- a/test/isTypedArray/isTypedArray.test.js +++ b/test/isTypedArray/isTypedArray.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const isTypedArray = require('./isTypedArray.js'); test('Testing isTypedArray', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isTypedArray === 'function', 'isTypedArray is a Function'); - //t.deepEqual(isTypedArray(args..), 'Expected'); - //t.equal(isTypedArray(args..), 'Expected'); - //t.false(isTypedArray(args..), 'Expected'); - //t.throws(isTypedArray(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isTypedArray === 'function', 'isTypedArray is a Function'); + //t.deepEqual(isTypedArray(args..), 'Expected'); + //t.equal(isTypedArray(args..), 'Expected'); + //t.false(isTypedArray(args..), 'Expected'); + //t.throws(isTypedArray(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isUndefined/isUndefined.js b/test/isUndefined/isUndefined.js index fa0f75d88..7eb3f9b03 100644 --- a/test/isUndefined/isUndefined.js +++ b/test/isUndefined/isUndefined.js @@ -1,2 +1,2 @@ const isUndefined = val => val === undefined; - module.exports = isUndefined \ No newline at end of file +module.exports = isUndefined \ No newline at end of file diff --git a/test/isUndefined/isUndefined.test.js b/test/isUndefined/isUndefined.test.js index 701faed0a..ce988c9ef 100644 --- a/test/isUndefined/isUndefined.test.js +++ b/test/isUndefined/isUndefined.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const isUndefined = require('./isUndefined.js'); test('Testing isUndefined', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isUndefined === 'function', 'isUndefined is a Function'); - //t.deepEqual(isUndefined(args..), 'Expected'); - //t.equal(isUndefined(args..), 'Expected'); - //t.false(isUndefined(args..), 'Expected'); - //t.throws(isUndefined(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isUndefined === 'function', 'isUndefined is a Function'); + //t.deepEqual(isUndefined(args..), 'Expected'); + //t.equal(isUndefined(args..), 'Expected'); + //t.false(isUndefined(args..), 'Expected'); + //t.throws(isUndefined(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isUpperCase/isUpperCase.js b/test/isUpperCase/isUpperCase.js index 319409a0b..9f255968e 100644 --- a/test/isUpperCase/isUpperCase.js +++ b/test/isUpperCase/isUpperCase.js @@ -1,2 +1,2 @@ const isUpperCase = str => str === str.toUpperCase(); - module.exports = isUpperCase \ No newline at end of file +module.exports = isUpperCase \ No newline at end of file diff --git a/test/isUpperCase/isUpperCase.test.js b/test/isUpperCase/isUpperCase.test.js index e42088f8e..a0b8e8a89 100644 --- a/test/isUpperCase/isUpperCase.test.js +++ b/test/isUpperCase/isUpperCase.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const isUpperCase = require('./isUpperCase.js'); test('Testing isUpperCase', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isUpperCase === 'function', 'isUpperCase is a Function'); - //t.deepEqual(isUpperCase(args..), 'Expected'); - t.equal(isUpperCase('ABC'), true, 'ABC is all upper case'); - t.equal(isUpperCase('abc'), false, 'abc is not all upper case'); - t.equal(isUpperCase('A3@$'), true, 'A3@$ is all uppercase'); - //t.false(isUpperCase(args..), 'Expected'); - //t.throws(isUpperCase(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isUpperCase === 'function', 'isUpperCase is a Function'); + //t.deepEqual(isUpperCase(args..), 'Expected'); + t.equal(isUpperCase('ABC'), true, 'ABC is all upper case'); + t.equal(isUpperCase('abc'), false, 'abc is not all upper case'); + t.equal(isUpperCase('A3@$'), true, 'A3@$ is all uppercase'); + //t.false(isUpperCase(args..), 'Expected'); + //t.throws(isUpperCase(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isValidJSON/isValidJSON.js b/test/isValidJSON/isValidJSON.js index c18f03a49..b06d5538c 100644 --- a/test/isValidJSON/isValidJSON.js +++ b/test/isValidJSON/isValidJSON.js @@ -6,4 +6,4 @@ return true; return false; } }; - module.exports = isValidJSON \ No newline at end of file +module.exports = isValidJSON \ No newline at end of file diff --git a/test/isValidJSON/isValidJSON.test.js b/test/isValidJSON/isValidJSON.test.js index 1c38c04d0..b0ad1dac5 100644 --- a/test/isValidJSON/isValidJSON.test.js +++ b/test/isValidJSON/isValidJSON.test.js @@ -2,15 +2,15 @@ const test = require('tape'); const isValidJSON = require('./isValidJSON.js'); test('Testing isValidJSON', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isValidJSON === 'function', 'isValidJSON is a Function'); - t.equal(isValidJSON('{"name":"Adam","age":20}'), true, '{"name":"Adam","age":20} is a valid JSON'); - t.equal(isValidJSON('{"name":"Adam",age:"20"}'), false, '{"name":"Adam",age:"20"} is not a valid JSON'); - t.equal(isValidJSON(null), true, 'null is a valid JSON'); - //t.deepEqual(isValidJSON(args..), 'Expected'); - //t.equal(isValidJSON(args..), 'Expected'); - //t.false(isValidJSON(args..), 'Expected'); - //t.throws(isValidJSON(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isValidJSON === 'function', 'isValidJSON is a Function'); + t.equal(isValidJSON('{"name":"Adam","age":20}'), true, '{"name":"Adam","age":20} is a valid JSON'); + t.equal(isValidJSON('{"name":"Adam",age:"20"}'), false, '{"name":"Adam",age:"20"} is not a valid JSON'); + t.equal(isValidJSON(null), true, 'null is a valid JSON'); + //t.deepEqual(isValidJSON(args..), 'Expected'); + //t.equal(isValidJSON(args..), 'Expected'); + //t.false(isValidJSON(args..), 'Expected'); + //t.throws(isValidJSON(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isWeakMap/isWeakMap.test.js b/test/isWeakMap/isWeakMap.test.js index f691dad74..72bb4544a 100644 --- a/test/isWeakMap/isWeakMap.test.js +++ b/test/isWeakMap/isWeakMap.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const isWeakMap = require('./isWeakMap.js'); test('Testing isWeakMap', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isWeakMap === 'function', 'isWeakMap is a Function'); - //t.deepEqual(isWeakMap(args..), 'Expected'); - //t.equal(isWeakMap(args..), 'Expected'); - //t.false(isWeakMap(args..), 'Expected'); - //t.throws(isWeakMap(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isWeakMap === 'function', 'isWeakMap is a Function'); + //t.deepEqual(isWeakMap(args..), 'Expected'); + //t.equal(isWeakMap(args..), 'Expected'); + //t.false(isWeakMap(args..), 'Expected'); + //t.throws(isWeakMap(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/isWeakSet/isWeakSet.test.js b/test/isWeakSet/isWeakSet.test.js index ca333cf3a..3bb390cde 100644 --- a/test/isWeakSet/isWeakSet.test.js +++ b/test/isWeakSet/isWeakSet.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const isWeakSet = require('./isWeakSet.js'); test('Testing isWeakSet', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof isWeakSet === 'function', 'isWeakSet is a Function'); - //t.deepEqual(isWeakSet(args..), 'Expected'); - //t.equal(isWeakSet(args..), 'Expected'); - //t.false(isWeakSet(args..), 'Expected'); - //t.throws(isWeakSet(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof isWeakSet === 'function', 'isWeakSet is a Function'); + //t.deepEqual(isWeakSet(args..), 'Expected'); + //t.equal(isWeakSet(args..), 'Expected'); + //t.false(isWeakSet(args..), 'Expected'); + //t.throws(isWeakSet(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/join/join.js b/test/join/join.js index 0d24968e8..7fc8e49f7 100644 --- a/test/join/join.js +++ b/test/join/join.js @@ -6,4 +6,4 @@ i == arr.length - 2 : i == arr.length - 1 ? acc + val : acc + val + separator, '' ); - module.exports = join \ No newline at end of file +module.exports = join \ No newline at end of file diff --git a/test/join/join.test.js b/test/join/join.test.js index e0238a7b7..385ef56b8 100644 --- a/test/join/join.test.js +++ b/test/join/join.test.js @@ -2,16 +2,16 @@ const test = require('tape'); const join = require('./join.js'); test('Testing join', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof join === 'function', 'join is a Function'); - t.deepEqual(join(['pen', 'pineapple', 'apple', 'pen'], ',', '&'), "pen,pineapple,apple&pen", "Joins all elements of an array into a string and returns this string"); - t.deepEqual(join(['pen', 'pineapple', 'apple', 'pen'], ','), "pen,pineapple,apple,pen", "Joins all elements of an array into a string and returns this string"); - t.deepEqual(join(['pen', 'pineapple', 'apple', 'pen']), "pen,pineapple,apple,pen", "Joins all elements of an array into a string and returns this string"); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof join === 'function', 'join is a Function'); + t.deepEqual(join(['pen', 'pineapple', 'apple', 'pen'], ',', '&'), "pen,pineapple,apple&pen", "Joins all elements of an array into a string and returns this string"); + t.deepEqual(join(['pen', 'pineapple', 'apple', 'pen'], ','), "pen,pineapple,apple,pen", "Joins all elements of an array into a string and returns this string"); + t.deepEqual(join(['pen', 'pineapple', 'apple', 'pen']), "pen,pineapple,apple,pen", "Joins all elements of an array into a string and returns this string"); - //t.deepEqual(join(args..), 'Expected'); - //t.equal(join(args..), 'Expected'); - //t.false(join(args..), 'Expected'); - //t.throws(join(args..), 'Expected'); - t.end(); + //t.deepEqual(join(args..), 'Expected'); + //t.equal(join(args..), 'Expected'); + //t.false(join(args..), 'Expected'); + //t.throws(join(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/last/last.js b/test/last/last.js index 294839092..322078184 100644 --- a/test/last/last.js +++ b/test/last/last.js @@ -1,2 +1,2 @@ const last = arr => arr[arr.length - 1]; - module.exports = last \ No newline at end of file +module.exports = last \ No newline at end of file diff --git a/test/last/last.test.js b/test/last/last.test.js index 528a363ab..fc0ba799c 100644 --- a/test/last/last.test.js +++ b/test/last/last.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const last = require('./last.js'); test('Testing last', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof last === 'function', 'last is a Function'); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof last === 'function', 'last is a Function'); t.true(last({ a: 1234}) === undefined, 'last({ a: 1234}) returns undefined'); t.equal(last([1, 2, 3]), 3, "last([1, 2, 3]) returns 3"); t.equal(last({ 0: false}), undefined, 'last({ 0: false}) returns undefined'); - t.equal(last('String'), 'g', 'last(String) returns g'); + t.equal(last('String'), 'g', 'last(String) returns g'); t.throws(() => last(null), 'last(null) throws an Error'); t.throws(() => last(undefined), 'last(undefined) throws an Error'); t.throws(() => last(), 'last() throws an Error'); @@ -17,5 +17,5 @@ test('Testing last', (t) => { last([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]); let end = new Date().getTime(); t.true((end - start) < 2000, 'last([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run'); - t.end(); + t.end(); }); \ No newline at end of file diff --git a/test/lcm/lcm.js b/test/lcm/lcm.js index fd197ae0c..871e8bdb9 100644 --- a/test/lcm/lcm.js +++ b/test/lcm/lcm.js @@ -3,4 +3,4 @@ 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 \ No newline at end of file +module.exports = lcm \ No newline at end of file diff --git a/test/lcm/lcm.test.js b/test/lcm/lcm.test.js index 469dce174..cba81345c 100644 --- a/test/lcm/lcm.test.js +++ b/test/lcm/lcm.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const lcm = require('./lcm.js'); test('Testing lcm', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof lcm === 'function', 'lcm is a Function'); - t.equal(lcm(12, 7), 84, "Returns the least common multiple of two or more numbers."); - t.equal(lcm(...[1, 3, 4, 5]), 60, "Returns the least common multiple of two or more numbers."); - //t.deepEqual(lcm(args..), 'Expected'); - //t.equal(lcm(args..), 'Expected'); - //t.false(lcm(args..), 'Expected'); - //t.throws(lcm(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof lcm === 'function', 'lcm is a Function'); + t.equal(lcm(12, 7), 84, "Returns the least common multiple of two or more numbers."); + t.equal(lcm(...[1, 3, 4, 5]), 60, "Returns the least common multiple of two or more numbers."); + //t.deepEqual(lcm(args..), 'Expected'); + //t.equal(lcm(args..), 'Expected'); + //t.false(lcm(args..), 'Expected'); + //t.throws(lcm(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/longestItem/longestItem.js b/test/longestItem/longestItem.js index 2df777176..9d1e5c007 100644 --- a/test/longestItem/longestItem.js +++ b/test/longestItem/longestItem.js @@ -1,2 +1,2 @@ const longestItem = (...vals) => [...vals].sort((a, b) => b.length - a.length)[0]; - module.exports = longestItem \ No newline at end of file +module.exports = longestItem \ No newline at end of file diff --git a/test/longestItem/longestItem.test.js b/test/longestItem/longestItem.test.js index 9e09b19c2..ae4b53739 100644 --- a/test/longestItem/longestItem.test.js +++ b/test/longestItem/longestItem.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const longestItem = require('./longestItem.js'); test('Testing longestItem', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof longestItem === 'function', 'longestItem is a Function'); - t.deepEqual(longestItem('this', 'is', 'a', 'testcase'), 'testcase', "Returns the longest object"); - //t.deepEqual(longestItem(args..), 'Expected'); - //t.equal(longestItem(args..), 'Expected'); - //t.false(longestItem(args..), 'Expected'); - //t.throws(longestItem(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof longestItem === 'function', 'longestItem is a Function'); + t.deepEqual(longestItem('this', 'is', 'a', 'testcase'), 'testcase', "Returns the longest object"); + //t.deepEqual(longestItem(args..), 'Expected'); + //t.equal(longestItem(args..), 'Expected'); + //t.false(longestItem(args..), 'Expected'); + //t.throws(longestItem(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/lowercaseKeys/lowercaseKeys.js b/test/lowercaseKeys/lowercaseKeys.js index 34abc71ff..5fafc126c 100644 --- a/test/lowercaseKeys/lowercaseKeys.js +++ b/test/lowercaseKeys/lowercaseKeys.js @@ -3,4 +3,4 @@ Object.keys(obj).reduce((acc, key) => { acc[key.toLowerCase()] = obj[key]; return acc; }, {}); - module.exports = lowercaseKeys \ No newline at end of file +module.exports = lowercaseKeys \ No newline at end of file diff --git a/test/lowercaseKeys/lowercaseKeys.test.js b/test/lowercaseKeys/lowercaseKeys.test.js index a3a697e00..d1069cb19 100644 --- a/test/lowercaseKeys/lowercaseKeys.test.js +++ b/test/lowercaseKeys/lowercaseKeys.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const lowercaseKeys = require('./lowercaseKeys.js'); test('Testing lowercaseKeys', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof lowercaseKeys === 'function', 'lowercaseKeys is a Function'); - //t.deepEqual(lowercaseKeys(args..), 'Expected'); - //t.equal(lowercaseKeys(args..), 'Expected'); - //t.false(lowercaseKeys(args..), 'Expected'); - //t.throws(lowercaseKeys(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof lowercaseKeys === 'function', 'lowercaseKeys is a Function'); + //t.deepEqual(lowercaseKeys(args..), 'Expected'); + //t.equal(lowercaseKeys(args..), 'Expected'); + //t.false(lowercaseKeys(args..), 'Expected'); + //t.throws(lowercaseKeys(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/luhnCheck/luhnCheck.js b/test/luhnCheck/luhnCheck.js index 240a8b0a3..b8742e21d 100644 --- a/test/luhnCheck/luhnCheck.js +++ b/test/luhnCheck/luhnCheck.js @@ -8,4 +8,4 @@ let sum = arr.reduce((acc, val, i) => (i % 2 !== 0 ? acc + val : acc + (val * 2) sum += lastDigit; return sum % 10 === 0; }; - module.exports = luhnCheck \ No newline at end of file +module.exports = luhnCheck \ No newline at end of file diff --git a/test/luhnCheck/luhnCheck.test.js b/test/luhnCheck/luhnCheck.test.js index b53fe9c36..e044cbd85 100644 --- a/test/luhnCheck/luhnCheck.test.js +++ b/test/luhnCheck/luhnCheck.test.js @@ -2,15 +2,15 @@ const test = require('tape'); const luhnCheck = require('./luhnCheck.js'); test('Testing luhnCheck', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof luhnCheck === 'function', 'luhnCheck is a Function'); - t.equal(luhnCheck(6011329933655299), false, "validates identification number"); - t.equal(luhnCheck('4485275742308327'), true, "validates identification number"); - t.equal(luhnCheck(123456789), false, "validates identification number"); - //t.deepEqual(luhnCheck(args..), 'Expected'); - //t.equal(luhnCheck(args..), 'Expected'); - //t.false(luhnCheck(args..), 'Expected'); - //t.throws(luhnCheck(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof luhnCheck === 'function', 'luhnCheck is a Function'); + t.equal(luhnCheck(6011329933655299), false, "validates identification number"); + t.equal(luhnCheck('4485275742308327'), true, "validates identification number"); + t.equal(luhnCheck(123456789), false, "validates identification number"); + //t.deepEqual(luhnCheck(args..), 'Expected'); + //t.equal(luhnCheck(args..), 'Expected'); + //t.false(luhnCheck(args..), 'Expected'); + //t.throws(luhnCheck(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/mapKeys/mapKeys.js b/test/mapKeys/mapKeys.js index 6d53b64c7..a1ca80202 100644 --- a/test/mapKeys/mapKeys.js +++ b/test/mapKeys/mapKeys.js @@ -3,4 +3,4 @@ Object.keys(obj).reduce((acc, k) => { acc[fn(obj[k], k, obj)] = obj[k]; return acc; }, {}); - module.exports = mapKeys \ No newline at end of file +module.exports = mapKeys \ No newline at end of file diff --git a/test/mapKeys/mapKeys.test.js b/test/mapKeys/mapKeys.test.js index a2b7ea63a..0522146fe 100644 --- a/test/mapKeys/mapKeys.test.js +++ b/test/mapKeys/mapKeys.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const mapKeys = require('./mapKeys.js'); test('Testing mapKeys', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof mapKeys === 'function', 'mapKeys is a Function'); - //t.deepEqual(mapKeys(args..), 'Expected'); - //t.equal(mapKeys(args..), 'Expected'); - //t.false(mapKeys(args..), 'Expected'); - //t.throws(mapKeys(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof mapKeys === 'function', 'mapKeys is a Function'); + //t.deepEqual(mapKeys(args..), 'Expected'); + //t.equal(mapKeys(args..), 'Expected'); + //t.false(mapKeys(args..), 'Expected'); + //t.throws(mapKeys(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/mapObject/mapObject.js b/test/mapObject/mapObject.js index 821847f1b..5bb4603c9 100644 --- a/test/mapObject/mapObject.js +++ b/test/mapObject/mapObject.js @@ -2,4 +2,4 @@ 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 \ No newline at end of file +module.exports = mapObject \ No newline at end of file diff --git a/test/mapObject/mapObject.test.js b/test/mapObject/mapObject.test.js index d534b43b0..044c43b19 100644 --- a/test/mapObject/mapObject.test.js +++ b/test/mapObject/mapObject.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const mapObject = require('./mapObject.js'); test('Testing mapObject', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof mapObject === 'function', 'mapObject is a Function'); - const squareIt = arr => mapObject(arr, a => a * a); - t.deepEqual(squareIt([1, 2, 3]), { 1: 1, 2: 4, 3: 9 }, "Maps the values of an array to an object using a function"); - //t.deepEqual(mapObject(args..), 'Expected'); - //t.equal(mapObject(args..), 'Expected'); - //t.false(mapObject(args..), 'Expected'); - //t.throws(mapObject(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof mapObject === 'function', 'mapObject is a Function'); + const squareIt = arr => mapObject(arr, a => a * a); + t.deepEqual(squareIt([1, 2, 3]), { 1: 1, 2: 4, 3: 9 }, "Maps the values of an array to an object using a function"); + //t.deepEqual(mapObject(args..), 'Expected'); + //t.equal(mapObject(args..), 'Expected'); + //t.false(mapObject(args..), 'Expected'); + //t.throws(mapObject(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/mapValues/mapValues.js b/test/mapValues/mapValues.js index bebb7700e..89f62920a 100644 --- a/test/mapValues/mapValues.js +++ b/test/mapValues/mapValues.js @@ -3,4 +3,4 @@ Object.keys(obj).reduce((acc, k) => { acc[k] = fn(obj[k], k, obj); return acc; }, {}); - module.exports = mapValues \ No newline at end of file +module.exports = mapValues \ No newline at end of file diff --git a/test/mapValues/mapValues.test.js b/test/mapValues/mapValues.test.js index e30e06c66..741e4f4f3 100644 --- a/test/mapValues/mapValues.test.js +++ b/test/mapValues/mapValues.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const mapValues = require('./mapValues.js'); test('Testing mapValues', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof mapValues === 'function', 'mapValues is a Function'); - //t.deepEqual(mapValues(args..), 'Expected'); - //t.equal(mapValues(args..), 'Expected'); - //t.false(mapValues(args..), 'Expected'); - //t.throws(mapValues(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof mapValues === 'function', 'mapValues is a Function'); + //t.deepEqual(mapValues(args..), 'Expected'); + //t.equal(mapValues(args..), 'Expected'); + //t.false(mapValues(args..), 'Expected'); + //t.throws(mapValues(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/mask/mask.js b/test/mask/mask.js index fab75a1ea..8f725dea7 100644 --- a/test/mask/mask.js +++ b/test/mask/mask.js @@ -1,3 +1,3 @@ const mask = (cc, num = 4, mask = '*') => ('' + cc).slice(0, -num).replace(/./g, mask) + ('' + cc).slice(-num); - module.exports = mask \ No newline at end of file +module.exports = mask \ No newline at end of file diff --git a/test/mask/mask.test.js b/test/mask/mask.test.js index b423586cf..dc57ed888 100644 --- a/test/mask/mask.test.js +++ b/test/mask/mask.test.js @@ -2,15 +2,15 @@ const test = require('tape'); const mask = require('./mask.js'); test('Testing mask', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof mask === 'function', 'mask is a Function'); - t.equal(mask(1234567890), '******7890', "Replaces all but the last num of characters with the specified mask character"); - t.equal(mask(1234567890, 3), '*******890', "Replaces all but the last num of characters with the specified mask character"); - t.equal(mask(1234567890, -4, '$'), '$$$$567890', "Replaces all but the last num of characters with the specified mask character"); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof mask === 'function', 'mask is a Function'); + t.equal(mask(1234567890), '******7890', "Replaces all but the last num of characters with the specified mask character"); + t.equal(mask(1234567890, 3), '*******890', "Replaces all but the last num of characters with the specified mask character"); + t.equal(mask(1234567890, -4, '$'), '$$$$567890', "Replaces all but the last num of characters with the specified mask character"); - //t.equal(mask(args..), 'Expected'); - //t.false(mask(args..), 'Expected'); - //t.throws(mask(args..), 'Expected'); - t.end(); + //t.equal(mask(args..), 'Expected'); + //t.false(mask(args..), 'Expected'); + //t.throws(mask(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/matches/matches.js b/test/matches/matches.js new file mode 100644 index 000000000..4c774e710 --- /dev/null +++ b/test/matches/matches.js @@ -0,0 +1,3 @@ +const matches = (obj, source) => +Object.keys(source).every(key => obj.hasOwnProperty(key) && obj[key] === source[key]); +module.exports = matches \ No newline at end of file diff --git a/test/matches/matches.test.js b/test/matches/matches.test.js new file mode 100644 index 000000000..82fd66a08 --- /dev/null +++ b/test/matches/matches.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const matches = require('./matches.js'); + +test('Testing matches', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof matches === 'function', 'matches is a Function'); + //t.deepEqual(matches(args..), 'Expected'); + //t.equal(matches(args..), 'Expected'); + //t.false(matches(args..), 'Expected'); + //t.throws(matches(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/matchesWith/matchesWith.js b/test/matchesWith/matchesWith.js new file mode 100644 index 000000000..0b9ae8d96 --- /dev/null +++ b/test/matchesWith/matchesWith.js @@ -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 \ No newline at end of file diff --git a/test/matchesWith/matchesWith.test.js b/test/matchesWith/matchesWith.test.js new file mode 100644 index 000000000..b7f696224 --- /dev/null +++ b/test/matchesWith/matchesWith.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const matchesWith = require('./matchesWith.js'); + +test('Testing matchesWith', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof matchesWith === 'function', 'matchesWith is a Function'); + //t.deepEqual(matchesWith(args..), 'Expected'); + //t.equal(matchesWith(args..), 'Expected'); + //t.false(matchesWith(args..), 'Expected'); + //t.throws(matchesWith(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/maxBy/maxBy.js b/test/maxBy/maxBy.js index 66cbfe8f6..68292b944 100644 --- a/test/maxBy/maxBy.js +++ b/test/maxBy/maxBy.js @@ -1,2 +1,2 @@ const maxBy = (arr, fn) => Math.max(...arr.map(typeof fn === 'function' ? fn : val => val[fn])); - module.exports = maxBy \ No newline at end of file +module.exports = maxBy \ No newline at end of file diff --git a/test/maxBy/maxBy.test.js b/test/maxBy/maxBy.test.js index 765bb73ec..3c0d156b3 100644 --- a/test/maxBy/maxBy.test.js +++ b/test/maxBy/maxBy.test.js @@ -2,12 +2,14 @@ const test = require('tape'); const maxBy = require('./maxBy.js'); test('Testing maxBy', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof maxBy === 'function', 'maxBy is a Function'); - //t.deepEqual(maxBy(args..), 'Expected'); - //t.equal(maxBy(args..), 'Expected'); - //t.false(maxBy(args..), 'Expected'); - //t.throws(maxBy(args..), 'Expected'); - t.end(); -}); \ No newline at end of file + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof maxBy === 'function', 'maxBy is a Function'); + t.equals(maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n), 8, 'Produces the right result with a function'); + t.equals(maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'), 8, 'Produces the right result with a property name'); + //t.deepEqual(maxBy(args..), 'Expected'); + //t.equal(maxBy(args..), 'Expected'); + //t.false(maxBy(args..), 'Expected'); + //t.throws(maxBy(args..), 'Expected'); + t.end(); +}); diff --git a/test/maxN/maxN.js b/test/maxN/maxN.js index d7da949d0..2883c00cc 100644 --- a/test/maxN/maxN.js +++ b/test/maxN/maxN.js @@ -1,2 +1,2 @@ const maxN = (arr, n = 1) => [...arr].sort((a, b) => b - a).slice(0, n); - module.exports = maxN \ No newline at end of file +module.exports = maxN \ No newline at end of file diff --git a/test/maxN/maxN.test.js b/test/maxN/maxN.test.js index 085f54341..89e14ab98 100644 --- a/test/maxN/maxN.test.js +++ b/test/maxN/maxN.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const maxN = require('./maxN.js'); test('Testing maxN', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof maxN === 'function', 'maxN is a Function'); - t.deepEqual(maxN([1, 2, 3]), [3], "Returns the n maximum elements from the provided array"); - t.deepEqual(maxN([1, 2, 3], 2), [3, 2], "Returns the n maximum elements from the provided array"); - //t.deepEqual(maxN(args..), 'Expected'); - //t.equal(maxN(args..), 'Expected'); - //t.false(maxN(args..), 'Expected'); - //t.throws(maxN(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof maxN === 'function', 'maxN is a Function'); + t.deepEqual(maxN([1, 2, 3]), [3], "Returns the n maximum elements from the provided array"); + t.deepEqual(maxN([1, 2, 3], 2), [3, 2], "Returns the n maximum elements from the provided array"); + //t.deepEqual(maxN(args..), 'Expected'); + //t.equal(maxN(args..), 'Expected'); + //t.false(maxN(args..), 'Expected'); + //t.throws(maxN(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/median/median.js b/test/median/median.js index 59f6c6641..63b0b2bdc 100644 --- a/test/median/median.js +++ b/test/median/median.js @@ -3,4 +3,4 @@ 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 \ No newline at end of file +module.exports = median \ No newline at end of file diff --git a/test/median/median.test.js b/test/median/median.test.js index bfb1a5cfc..9fa44be9c 100644 --- a/test/median/median.test.js +++ b/test/median/median.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const median = require('./median.js'); test('Testing median', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof median === 'function', 'median is a Function'); - t.equal(median([5, 6, 50, 1, -5]), 5, "Returns the median of an array of numbers"); - t.equal(median([1, 2, 3]), 2, "Returns the median of an array of numbers"); - //t.deepEqual(median(args..), 'Expected'); - //t.equal(median(args..), 'Expected'); - //t.false(median(args..), 'Expected'); - //t.throws(median(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof median === 'function', 'median is a Function'); + t.equal(median([5, 6, 50, 1, -5]), 5, "Returns the median of an array of numbers"); + t.equal(median([1, 2, 3]), 2, "Returns the median of an array of numbers"); + //t.deepEqual(median(args..), 'Expected'); + //t.equal(median(args..), 'Expected'); + //t.false(median(args..), 'Expected'); + //t.throws(median(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/memoize/memoize.js b/test/memoize/memoize.js index 6f7ebc106..f95372c10 100644 --- a/test/memoize/memoize.js +++ b/test/memoize/memoize.js @@ -6,4 +6,4 @@ return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && c cached.cache = cache; return cached; }; - module.exports = memoize \ No newline at end of file +module.exports = memoize \ No newline at end of file diff --git a/test/memoize/memoize.test.js b/test/memoize/memoize.test.js index cf045ba86..d6eee6068 100644 --- a/test/memoize/memoize.test.js +++ b/test/memoize/memoize.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const memoize = require('./memoize.js'); test('Testing memoize', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof memoize === 'function', 'memoize is a Function'); - //t.deepEqual(memoize(args..), 'Expected'); - //t.equal(memoize(args..), 'Expected'); - //t.false(memoize(args..), 'Expected'); - //t.throws(memoize(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof memoize === 'function', 'memoize is a Function'); + //t.deepEqual(memoize(args..), 'Expected'); + //t.equal(memoize(args..), 'Expected'); + //t.false(memoize(args..), 'Expected'); + //t.throws(memoize(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/merge/merge.js b/test/merge/merge.js index bc9774fb4..5a816f96f 100644 --- a/test/merge/merge.js +++ b/test/merge/merge.js @@ -7,4 +7,4 @@ return acc; }, {}), {} ); - module.exports = merge \ No newline at end of file +module.exports = merge \ No newline at end of file diff --git a/test/merge/merge.test.js b/test/merge/merge.test.js index 28ade12bd..1ed749488 100644 --- a/test/merge/merge.test.js +++ b/test/merge/merge.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const merge = require('./merge.js'); test('Testing merge', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof merge === 'function', 'merge is a Function'); - //t.deepEqual(merge(args..), 'Expected'); - //t.equal(merge(args..), 'Expected'); - //t.false(merge(args..), 'Expected'); - //t.throws(merge(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof merge === 'function', 'merge is a Function'); + //t.deepEqual(merge(args..), 'Expected'); + //t.equal(merge(args..), 'Expected'); + //t.false(merge(args..), 'Expected'); + //t.throws(merge(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/minBy/minBy.js b/test/minBy/minBy.js index 135bbecb3..c5a3505dd 100644 --- a/test/minBy/minBy.js +++ b/test/minBy/minBy.js @@ -1,2 +1,2 @@ const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : val => val[fn])); - module.exports = minBy \ No newline at end of file +module.exports = minBy \ No newline at end of file diff --git a/test/minBy/minBy.test.js b/test/minBy/minBy.test.js index 130b2de7e..f2a0ca5ff 100644 --- a/test/minBy/minBy.test.js +++ b/test/minBy/minBy.test.js @@ -2,12 +2,14 @@ const test = require('tape'); const minBy = require('./minBy.js'); test('Testing minBy', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof minBy === 'function', 'minBy is a Function'); - //t.deepEqual(minBy(args..), 'Expected'); - //t.equal(minBy(args..), 'Expected'); - //t.false(minBy(args..), 'Expected'); - //t.throws(minBy(args..), 'Expected'); - t.end(); -}); \ No newline at end of file + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof minBy === 'function', 'minBy is a Function'); + t.equals(minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n), 2, 'Produces the right result with a function'); + t.equals(minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'), 2, 'Produces the right result with a property name'); + //t.deepEqual(minBy(args..), 'Expected'); + //t.equal(minBy(args..), 'Expected'); + //t.false(minBy(args..), 'Expected'); + //t.throws(minBy(args..), 'Expected'); + t.end(); +}); diff --git a/test/minN/minN.js b/test/minN/minN.js index 18b052d21..1a6974e9e 100644 --- a/test/minN/minN.js +++ b/test/minN/minN.js @@ -1,2 +1,2 @@ const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n); - module.exports = minN \ No newline at end of file +module.exports = minN \ No newline at end of file diff --git a/test/minN/minN.test.js b/test/minN/minN.test.js index 6d0460bf5..edfd36631 100644 --- a/test/minN/minN.test.js +++ b/test/minN/minN.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const minN = require('./minN.js'); test('Testing minN', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof minN === 'function', 'minN is a Function'); - t.deepEqual(minN([1, 2, 3]), [1], "Returns the n minimum elements from the provided array"); - t.deepEqual(minN([1, 2, 3], 2), [1, 2], "Returns the n minimum elements from the provided array"); - //t.equal(minN(args..), 'Expected'); - //t.false(minN(args..), 'Expected'); - //t.throws(minN(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof minN === 'function', 'minN is a Function'); + t.deepEqual(minN([1, 2, 3]), [1], "Returns the n minimum elements from the provided array"); + t.deepEqual(minN([1, 2, 3], 2), [1, 2], "Returns the n minimum elements from the provided array"); + //t.equal(minN(args..), 'Expected'); + //t.false(minN(args..), 'Expected'); + //t.throws(minN(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/negate/negate.js b/test/negate/negate.js index 65a7033e3..228a224f0 100644 --- a/test/negate/negate.js +++ b/test/negate/negate.js @@ -1,2 +1,2 @@ const negate = func => (...args) => !func(...args); - module.exports = negate \ No newline at end of file +module.exports = negate \ No newline at end of file diff --git a/test/negate/negate.test.js b/test/negate/negate.test.js index 0f761e218..8e85ef475 100644 --- a/test/negate/negate.test.js +++ b/test/negate/negate.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const negate = require('./negate.js'); test('Testing negate', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof negate === 'function', 'negate is a Function'); - t.deepEqual([1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 == 0)), [1, 3, 5], "Negates a predicate function"); - //t.deepEqual(negate(args..), 'Expected'); - //t.equal(negate(args..), 'Expected'); - //t.false(negate(args..), 'Expected'); - //t.throws(negate(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof negate === 'function', 'negate is a Function'); + t.deepEqual([1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 == 0)), [1, 3, 5], "Negates a predicate function"); + //t.deepEqual(negate(args..), 'Expected'); + //t.equal(negate(args..), 'Expected'); + //t.false(negate(args..), 'Expected'); + //t.throws(negate(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/nthArg/nthArg.js b/test/nthArg/nthArg.js new file mode 100644 index 000000000..a43475e8a --- /dev/null +++ b/test/nthArg/nthArg.js @@ -0,0 +1,2 @@ +const nthArg = n => (...args) => args.slice(n)[0]; +module.exports = nthArg \ No newline at end of file diff --git a/test/nthArg/nthArg.test.js b/test/nthArg/nthArg.test.js new file mode 100644 index 000000000..6061c25e9 --- /dev/null +++ b/test/nthArg/nthArg.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const nthArg = require('./nthArg.js'); + +test('Testing nthArg', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof nthArg === 'function', 'nthArg is a Function'); + //t.deepEqual(nthArg(args..), 'Expected'); + //t.equal(nthArg(args..), 'Expected'); + //t.false(nthArg(args..), 'Expected'); + //t.throws(nthArg(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/nthElement/nthElement.js b/test/nthElement/nthElement.js index 0fb6ce650..2e88831c1 100644 --- a/test/nthElement/nthElement.js +++ b/test/nthElement/nthElement.js @@ -1,2 +1,2 @@ const nthElement = (arr, n = 0) => (n > 0 ? arr.slice(n, n + 1) : arr.slice(n))[0]; - module.exports = nthElement \ No newline at end of file +module.exports = nthElement \ No newline at end of file diff --git a/test/nthElement/nthElement.test.js b/test/nthElement/nthElement.test.js index 4628abcda..6db6ddd4a 100644 --- a/test/nthElement/nthElement.test.js +++ b/test/nthElement/nthElement.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const nthElement = require('./nthElement.js'); test('Testing nthElement', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof nthElement === 'function', 'nthElement is a Function'); - t.equal(nthElement(['a', 'b', 'c'], 1), 'b', "Returns the nth element of an array."); - t.equal(nthElement(['a', 'b', 'c'], -3), 'a', "Returns the nth element of an array."); - //t.deepEqual(nthElement(args..), 'Expected'); - //t.equal(nthElement(args..), 'Expected'); - //t.false(nthElement(args..), 'Expected'); - //t.throws(nthElement(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof nthElement === 'function', 'nthElement is a Function'); + t.equal(nthElement(['a', 'b', 'c'], 1), 'b', "Returns the nth element of an array."); + t.equal(nthElement(['a', 'b', 'c'], -3), 'a', "Returns the nth element of an array."); + //t.deepEqual(nthElement(args..), 'Expected'); + //t.equal(nthElement(args..), 'Expected'); + //t.false(nthElement(args..), 'Expected'); + //t.throws(nthElement(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/objectFromPairs/objectFromPairs.js b/test/objectFromPairs/objectFromPairs.js index 2114c882f..a51048410 100644 --- a/test/objectFromPairs/objectFromPairs.js +++ b/test/objectFromPairs/objectFromPairs.js @@ -1,2 +1,2 @@ const objectFromPairs = arr => arr.reduce((a, v) => ((a[v[0]] = v[1]), a), {}); - module.exports = objectFromPairs \ No newline at end of file +module.exports = objectFromPairs \ No newline at end of file diff --git a/test/objectFromPairs/objectFromPairs.test.js b/test/objectFromPairs/objectFromPairs.test.js index a661ac37f..af270b7cf 100644 --- a/test/objectFromPairs/objectFromPairs.test.js +++ b/test/objectFromPairs/objectFromPairs.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const objectFromPairs = require('./objectFromPairs.js'); test('Testing objectFromPairs', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof objectFromPairs === 'function', 'objectFromPairs is a Function'); - t.deepEqual(objectFromPairs([['a', 1], ['b', 2]]), {a: 1, b: 2}, "Creates an object from the given key-value pairs."); - //t.deepEqual(objectFromPairs(args..), 'Expected'); - //t.equal(objectFromPairs(args..), 'Expected'); - //t.false(objectFromPairs(args..), 'Expected'); - //t.throws(objectFromPairs(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof objectFromPairs === 'function', 'objectFromPairs is a Function'); + t.deepEqual(objectFromPairs([['a', 1], ['b', 2]]), {a: 1, b: 2}, "Creates an object from the given key-value pairs."); + //t.deepEqual(objectFromPairs(args..), 'Expected'); + //t.equal(objectFromPairs(args..), 'Expected'); + //t.false(objectFromPairs(args..), 'Expected'); + //t.throws(objectFromPairs(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/objectToPairs/objectToPairs.js b/test/objectToPairs/objectToPairs.js index 0f06a0cbe..1f09bf226 100644 --- a/test/objectToPairs/objectToPairs.js +++ b/test/objectToPairs/objectToPairs.js @@ -1,2 +1,2 @@ const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]); - module.exports = objectToPairs \ No newline at end of file +module.exports = objectToPairs \ No newline at end of file diff --git a/test/objectToPairs/objectToPairs.test.js b/test/objectToPairs/objectToPairs.test.js index 087092236..e3477d39b 100644 --- a/test/objectToPairs/objectToPairs.test.js +++ b/test/objectToPairs/objectToPairs.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const objectToPairs = require('./objectToPairs.js'); test('Testing objectToPairs', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof objectToPairs === 'function', 'objectToPairs is a Function'); - t.deepEqual(objectToPairs({ a: 1, b: 2 }), [['a',1],['b',2]], "Creates an array of key-value pair arrays from an object."); - //t.deepEqual(objectToPairs(args..), 'Expected'); - //t.equal(objectToPairs(args..), 'Expected'); - //t.false(objectToPairs(args..), 'Expected'); - //t.throws(objectToPairs(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof objectToPairs === 'function', 'objectToPairs is a Function'); + t.deepEqual(objectToPairs({ a: 1, b: 2 }), [['a',1],['b',2]], "Creates an array of key-value pair arrays from an object."); + //t.deepEqual(objectToPairs(args..), 'Expected'); + //t.equal(objectToPairs(args..), 'Expected'); + //t.false(objectToPairs(args..), 'Expected'); + //t.throws(objectToPairs(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/observeMutations/observeMutations.js b/test/observeMutations/observeMutations.js index 065f7fff3..ab05e3fef 100644 --- a/test/observeMutations/observeMutations.js +++ b/test/observeMutations/observeMutations.js @@ -16,4 +16,4 @@ options ); return observer; }; - module.exports = observeMutations \ No newline at end of file +module.exports = observeMutations \ No newline at end of file diff --git a/test/observeMutations/observeMutations.test.js b/test/observeMutations/observeMutations.test.js index eca8ff0d4..0c6d479a7 100644 --- a/test/observeMutations/observeMutations.test.js +++ b/test/observeMutations/observeMutations.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const observeMutations = require('./observeMutations.js'); test('Testing observeMutations', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof observeMutations === 'function', 'observeMutations is a Function'); - //t.deepEqual(observeMutations(args..), 'Expected'); - //t.equal(observeMutations(args..), 'Expected'); - //t.false(observeMutations(args..), 'Expected'); - //t.throws(observeMutations(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof observeMutations === 'function', 'observeMutations is a Function'); + //t.deepEqual(observeMutations(args..), 'Expected'); + //t.equal(observeMutations(args..), 'Expected'); + //t.false(observeMutations(args..), 'Expected'); + //t.throws(observeMutations(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/off/off.js b/test/off/off.js index 94c2aa43d..fb19a0434 100644 --- a/test/off/off.js +++ b/test/off/off.js @@ -1,2 +1,2 @@ const off = (el, evt, fn, opts = false) => el.removeEventListener(evt, fn, opts); - module.exports = off \ No newline at end of file +module.exports = off \ No newline at end of file diff --git a/test/off/off.test.js b/test/off/off.test.js index b2cbbde08..030e7797a 100644 --- a/test/off/off.test.js +++ b/test/off/off.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const off = require('./off.js'); test('Testing off', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof off === 'function', 'off is a Function'); - //t.deepEqual(off(args..), 'Expected'); - //t.equal(off(args..), 'Expected'); - //t.false(off(args..), 'Expected'); - //t.throws(off(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof off === 'function', 'off is a Function'); + //t.deepEqual(off(args..), 'Expected'); + //t.equal(off(args..), 'Expected'); + //t.false(off(args..), 'Expected'); + //t.throws(off(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/omit/omit.js b/test/omit/omit.js new file mode 100644 index 000000000..3963ed455 --- /dev/null +++ b/test/omit/omit.js @@ -0,0 +1,5 @@ +const omit = (obj, arr) => +Object.keys(obj) +.filter(k => !arr.includes(k)) +.reduce((acc, key) => ((acc[key] = obj[key]), acc), {}); +module.exports = omit \ No newline at end of file diff --git a/test/omit/omit.test.js b/test/omit/omit.test.js new file mode 100644 index 000000000..27f191a04 --- /dev/null +++ b/test/omit/omit.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const omit = require('./omit.js'); + +test('Testing omit', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof omit === 'function', 'omit is a Function'); + //t.deepEqual(omit(args..), 'Expected'); + //t.equal(omit(args..), 'Expected'); + //t.false(omit(args..), 'Expected'); + //t.throws(omit(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/omitBy/omitBy.js b/test/omitBy/omitBy.js new file mode 100644 index 000000000..3beabf15d --- /dev/null +++ b/test/omitBy/omitBy.js @@ -0,0 +1,5 @@ +const omitBy = (obj, fn) => +Object.keys(obj) +.filter(k => !fn(obj[k], k)) +.reduce((acc, key) => ((acc[key] = obj[key]), acc), {}); +module.exports = omitBy \ No newline at end of file diff --git a/test/omitBy/omitBy.test.js b/test/omitBy/omitBy.test.js new file mode 100644 index 000000000..c103338a8 --- /dev/null +++ b/test/omitBy/omitBy.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const omitBy = require('./omitBy.js'); + +test('Testing omitBy', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof omitBy === 'function', 'omitBy is a Function'); + //t.deepEqual(omitBy(args..), 'Expected'); + //t.equal(omitBy(args..), 'Expected'); + //t.false(omitBy(args..), 'Expected'); + //t.throws(omitBy(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/on/on.js b/test/on/on.js index 12c958ab5..a8f53f65c 100644 --- a/test/on/on.js +++ b/test/on/on.js @@ -3,4 +3,4 @@ const delegatorFn = e => e.target.matches(opts.target) && fn.call(e.target, e); el.addEventListener(evt, opts.target ? delegatorFn : fn, opts.options || false); if (opts.target) return delegatorFn; }; - module.exports = on \ No newline at end of file +module.exports = on \ No newline at end of file diff --git a/test/on/on.test.js b/test/on/on.test.js index 15a242fa9..5bfa58a76 100644 --- a/test/on/on.test.js +++ b/test/on/on.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const on = require('./on.js'); test('Testing on', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof on === 'function', 'on is a Function'); - //t.deepEqual(on(args..), 'Expected'); - //t.equal(on(args..), 'Expected'); - //t.false(on(args..), 'Expected'); - //t.throws(on(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof on === 'function', 'on is a Function'); + //t.deepEqual(on(args..), 'Expected'); + //t.equal(on(args..), 'Expected'); + //t.false(on(args..), 'Expected'); + //t.throws(on(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/onUserInputChange/onUserInputChange.js b/test/onUserInputChange/onUserInputChange.js index 13cd2b44f..1850c9dec 100644 --- a/test/onUserInputChange/onUserInputChange.js +++ b/test/onUserInputChange/onUserInputChange.js @@ -12,4 +12,4 @@ if (type === 'touch') return; (type = 'touch'), callback(type), document.addEventListener('mousemove', mousemoveHandler); }); }; - module.exports = onUserInputChange \ No newline at end of file +module.exports = onUserInputChange \ No newline at end of file diff --git a/test/onUserInputChange/onUserInputChange.test.js b/test/onUserInputChange/onUserInputChange.test.js index ee4b3dc14..c4c181806 100644 --- a/test/onUserInputChange/onUserInputChange.test.js +++ b/test/onUserInputChange/onUserInputChange.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const onUserInputChange = require('./onUserInputChange.js'); test('Testing onUserInputChange', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof onUserInputChange === 'function', 'onUserInputChange is a Function'); - //t.deepEqual(onUserInputChange(args..), 'Expected'); - //t.equal(onUserInputChange(args..), 'Expected'); - //t.false(onUserInputChange(args..), 'Expected'); - //t.throws(onUserInputChange(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof onUserInputChange === 'function', 'onUserInputChange is a Function'); + //t.deepEqual(onUserInputChange(args..), 'Expected'); + //t.equal(onUserInputChange(args..), 'Expected'); + //t.false(onUserInputChange(args..), 'Expected'); + //t.throws(onUserInputChange(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/once/once.js b/test/once/once.js index 36225aa17..35f512e35 100644 --- a/test/once/once.js +++ b/test/once/once.js @@ -6,4 +6,4 @@ called = true; return fn.apply(this, args); }; }; - module.exports = once \ No newline at end of file +module.exports = once \ No newline at end of file diff --git a/test/once/once.test.js b/test/once/once.test.js index bc0742b89..6d457fe01 100644 --- a/test/once/once.test.js +++ b/test/once/once.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const once = require('./once.js'); test('Testing once', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof once === 'function', 'once is a Function'); - //t.deepEqual(once(args..), 'Expected'); - //t.equal(once(args..), 'Expected'); - //t.false(once(args..), 'Expected'); - //t.throws(once(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof once === 'function', 'once is a Function'); + //t.deepEqual(once(args..), 'Expected'); + //t.equal(once(args..), 'Expected'); + //t.false(once(args..), 'Expected'); + //t.throws(once(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/orderBy/orderBy.js b/test/orderBy/orderBy.js index e7db465e5..ae7f113c7 100644 --- a/test/orderBy/orderBy.js +++ b/test/orderBy/orderBy.js @@ -8,4 +8,4 @@ acc = p1 > p2 ? 1 : p1 < p2 ? -1 : 0; return acc; }, 0) ); - module.exports = orderBy \ No newline at end of file +module.exports = orderBy \ No newline at end of file diff --git a/test/orderBy/orderBy.test.js b/test/orderBy/orderBy.test.js index 4ee8706a2..2a721f61e 100644 --- a/test/orderBy/orderBy.test.js +++ b/test/orderBy/orderBy.test.js @@ -2,15 +2,15 @@ const test = require('tape'); const orderBy = require('./orderBy.js'); test('Testing orderBy', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof orderBy === 'function', 'orderBy is a Function'); - const users = [{ name: 'fred', age: 48 }, { name: 'barney', age: 36 }, { name: 'fred', age: 40 }]; - t.deepEqual(orderBy(users, ['name', 'age'], ['asc', 'desc']), [{name: 'barney', age: 36}, {name: 'fred', age: 48}, {name: 'fred', age: 40}], "Returns a sorted array of objects ordered by properties and orders."); - t.deepEqual(orderBy(users, ['name', 'age']), [{name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}], "Returns a sorted array of objects ordered by properties and orders."); - //t.deepEqual(orderBy(args..), 'Expected'); - //t.equal(orderBy(args..), 'Expected'); - //t.false(orderBy(args..), 'Expected'); - //t.throws(orderBy(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof orderBy === 'function', 'orderBy is a Function'); + const users = [{ name: 'fred', age: 48 }, { name: 'barney', age: 36 }, { name: 'fred', age: 40 }]; + t.deepEqual(orderBy(users, ['name', 'age'], ['asc', 'desc']), [{name: 'barney', age: 36}, {name: 'fred', age: 48}, {name: 'fred', age: 40}], "Returns a sorted array of objects ordered by properties and orders."); + t.deepEqual(orderBy(users, ['name', 'age']), [{name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}], "Returns a sorted array of objects ordered by properties and orders."); + //t.deepEqual(orderBy(args..), 'Expected'); + //t.equal(orderBy(args..), 'Expected'); + //t.false(orderBy(args..), 'Expected'); + //t.throws(orderBy(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/over/over.js b/test/over/over.js new file mode 100644 index 000000000..5a972c2f7 --- /dev/null +++ b/test/over/over.js @@ -0,0 +1,2 @@ +const over = (...fns) => (...args) => fns.map(fn => fn.apply(null, args)); +module.exports = over \ No newline at end of file diff --git a/test/over/over.test.js b/test/over/over.test.js new file mode 100644 index 000000000..e7ef99156 --- /dev/null +++ b/test/over/over.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const over = require('./over.js'); + +test('Testing over', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof over === 'function', 'over is a Function'); + //t.deepEqual(over(args..), 'Expected'); + //t.equal(over(args..), 'Expected'); + //t.false(over(args..), 'Expected'); + //t.throws(over(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/palindrome/palindrome.js b/test/palindrome/palindrome.js index 59557dcd3..1b17b4023 100644 --- a/test/palindrome/palindrome.js +++ b/test/palindrome/palindrome.js @@ -8,4 +8,4 @@ s .join('') ); }; - module.exports = palindrome \ No newline at end of file +module.exports = palindrome \ No newline at end of file diff --git a/test/palindrome/palindrome.test.js b/test/palindrome/palindrome.test.js index 0c4076cdd..2c65f5995 100644 --- a/test/palindrome/palindrome.test.js +++ b/test/palindrome/palindrome.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const palindrome = require('./palindrome.js'); test('Testing palindrome', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof palindrome === 'function', 'palindrome is a Function'); - t.equal(palindrome('taco cat'), true, "Given string is a palindrome"); - t.equal(palindrome('foobar'), false, "Given string is not a palindrome"); - //t.deepEqual(palindrome(args..), 'Expected'); - //t.equal(palindrome(args..), 'Expected'); - //t.false(palindrome(args..), 'Expected'); - //t.throws(palindrome(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof palindrome === 'function', 'palindrome is a Function'); + t.equal(palindrome('taco cat'), true, "Given string is a palindrome"); + t.equal(palindrome('foobar'), false, "Given string is not a palindrome"); + //t.deepEqual(palindrome(args..), 'Expected'); + //t.equal(palindrome(args..), 'Expected'); + //t.false(palindrome(args..), 'Expected'); + //t.throws(palindrome(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/parseCookie/parseCookie.js b/test/parseCookie/parseCookie.js index 20dcb1039..63656448c 100644 --- a/test/parseCookie/parseCookie.js +++ b/test/parseCookie/parseCookie.js @@ -6,4 +6,4 @@ str acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(v[1].trim()); return acc; }, {}); - module.exports = parseCookie \ No newline at end of file +module.exports = parseCookie \ No newline at end of file diff --git a/test/parseCookie/parseCookie.test.js b/test/parseCookie/parseCookie.test.js index 76a02bbe2..16ba1a6ad 100644 --- a/test/parseCookie/parseCookie.test.js +++ b/test/parseCookie/parseCookie.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const parseCookie = require('./parseCookie.js'); test('Testing parseCookie', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof parseCookie === 'function', 'parseCookie is a Function'); - //t.deepEqual(parseCookie(args..), 'Expected'); - //t.equal(parseCookie(args..), 'Expected'); - //t.false(parseCookie(args..), 'Expected'); - //t.throws(parseCookie(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof parseCookie === 'function', 'parseCookie is a Function'); + //t.deepEqual(parseCookie(args..), 'Expected'); + //t.equal(parseCookie(args..), 'Expected'); + //t.false(parseCookie(args..), 'Expected'); + //t.throws(parseCookie(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/partial/partial.js b/test/partial/partial.js new file mode 100644 index 000000000..c6e9b012a --- /dev/null +++ b/test/partial/partial.js @@ -0,0 +1,2 @@ +const partial = (fn, ...partials) => (...args) => fn(...partials, ...args); +module.exports = partial \ No newline at end of file diff --git a/test/partial/partial.test.js b/test/partial/partial.test.js new file mode 100644 index 000000000..763548f40 --- /dev/null +++ b/test/partial/partial.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const partial = require('./partial.js'); + +test('Testing partial', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof partial === 'function', 'partial is a Function'); + //t.deepEqual(partial(args..), 'Expected'); + //t.equal(partial(args..), 'Expected'); + //t.false(partial(args..), 'Expected'); + //t.throws(partial(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/partialRight/partialRight.js b/test/partialRight/partialRight.js new file mode 100644 index 000000000..20b89052d --- /dev/null +++ b/test/partialRight/partialRight.js @@ -0,0 +1,2 @@ +const partialRight = (fn, ...partials) => (...args) => fn(...args, ...partials); +module.exports = partialRight \ No newline at end of file diff --git a/test/partialRight/partialRight.test.js b/test/partialRight/partialRight.test.js new file mode 100644 index 000000000..7fda308da --- /dev/null +++ b/test/partialRight/partialRight.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const partialRight = require('./partialRight.js'); + +test('Testing partialRight', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof partialRight === 'function', 'partialRight is a Function'); + //t.deepEqual(partialRight(args..), 'Expected'); + //t.equal(partialRight(args..), 'Expected'); + //t.false(partialRight(args..), 'Expected'); + //t.throws(partialRight(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/partition/partition.js b/test/partition/partition.js index 9acd0309f..3e03d4e52 100644 --- a/test/partition/partition.js +++ b/test/partition/partition.js @@ -6,4 +6,4 @@ return acc; }, [[], []] ); - module.exports = partition \ No newline at end of file +module.exports = partition \ No newline at end of file diff --git a/test/partition/partition.test.js b/test/partition/partition.test.js index fec483e88..429fae050 100644 --- a/test/partition/partition.test.js +++ b/test/partition/partition.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const partition = require('./partition.js'); test('Testing partition', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof partition === 'function', 'partition is a Function'); - const users = [{ user: 'barney', age: 36, active: false }, { user: 'fred', age: 40, active: true }]; - t.deepEqual(partition(users, o => o.active), [[{ 'user': 'fred', 'age': 40, 'active': true }],[{ 'user': 'barney', 'age': 36, 'active': false }]], "Groups the elements into two arrays, depending on the provided function's truthiness for each element."); - //t.deepEqual(partition(args..), 'Expected'); - //t.equal(partition(args..), 'Expected'); - //t.false(partition(args..), 'Expected'); - //t.throws(partition(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof partition === 'function', 'partition is a Function'); + const users = [{ user: 'barney', age: 36, active: false }, { user: 'fred', age: 40, active: true }]; + t.deepEqual(partition(users, o => o.active), [[{ 'user': 'fred', 'age': 40, 'active': true }],[{ 'user': 'barney', 'age': 36, 'active': false }]], "Groups the elements into two arrays, depending on the provided function's truthiness for each element."); + //t.deepEqual(partition(args..), 'Expected'); + //t.equal(partition(args..), 'Expected'); + //t.false(partition(args..), 'Expected'); + //t.throws(partition(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/percentile/percentile.js b/test/percentile/percentile.js index b345bb0d8..45e69c0a6 100644 --- a/test/percentile/percentile.js +++ b/test/percentile/percentile.js @@ -1,3 +1,3 @@ const percentile = (arr, val) => 100 * arr.reduce((acc, v) => acc + (v < val ? 1 : 0) + (v === val ? 0.5 : 0), 0) / arr.length; - module.exports = percentile \ No newline at end of file +module.exports = percentile \ No newline at end of file diff --git a/test/percentile/percentile.test.js b/test/percentile/percentile.test.js index 573076404..63cf07868 100644 --- a/test/percentile/percentile.test.js +++ b/test/percentile/percentile.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const percentile = require('./percentile.js'); test('Testing percentile', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof percentile === 'function', 'percentile is a Function'); - t.equal(percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6), 55, "Uses the percentile formula to calculate how many numbers in the given array are less or equal to the given value."); - //t.deepEqual(percentile(args..), 'Expected'); - //t.equal(percentile(args..), 'Expected'); - //t.false(percentile(args..), 'Expected'); - //t.throws(percentile(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof percentile === 'function', 'percentile is a Function'); + t.equal(percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6), 55, "Uses the percentile formula to calculate how many numbers in the given array are less or equal to the given value."); + //t.deepEqual(percentile(args..), 'Expected'); + //t.equal(percentile(args..), 'Expected'); + //t.false(percentile(args..), 'Expected'); + //t.throws(percentile(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/pick/pick.js b/test/pick/pick.js index 465a5373a..649a25a9b 100644 --- a/test/pick/pick.js +++ b/test/pick/pick.js @@ -1,3 +1,3 @@ const pick = (obj, arr) => arr.reduce((acc, curr) => (curr in obj && (acc[curr] = obj[curr]), acc), {}); - module.exports = pick \ No newline at end of file +module.exports = pick \ No newline at end of file diff --git a/test/pick/pick.test.js b/test/pick/pick.test.js index 9a1a66aee..61565a0a2 100644 --- a/test/pick/pick.test.js +++ b/test/pick/pick.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const pick = require('./pick.js'); test('Testing pick', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof pick === 'function', 'pick is a Function'); - t.deepEqual(pick({ a: 1, b: '2', c: 3 }, ['a', 'c']), { 'a': 1, 'c': 3 }, "Picks the key-value pairs corresponding to the given keys from an object."); - //t.deepEqual(pick(args..), 'Expected'); - //t.equal(pick(args..), 'Expected'); - //t.false(pick(args..), 'Expected'); - //t.throws(pick(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof pick === 'function', 'pick is a Function'); + t.deepEqual(pick({ a: 1, b: '2', c: 3 }, ['a', 'c']), { 'a': 1, 'c': 3 }, "Picks the key-value pairs corresponding to the given keys from an object."); + //t.deepEqual(pick(args..), 'Expected'); + //t.equal(pick(args..), 'Expected'); + //t.false(pick(args..), 'Expected'); + //t.throws(pick(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/pickBy/pickBy.js b/test/pickBy/pickBy.js new file mode 100644 index 000000000..f8671e0bb --- /dev/null +++ b/test/pickBy/pickBy.js @@ -0,0 +1,5 @@ +const pickBy = (obj, fn) => +Object.keys(obj) +.filter(k => fn(obj[k], k)) +.reduce((acc, key) => ((acc[key] = obj[key]), acc), {}); +module.exports = pickBy \ No newline at end of file diff --git a/test/pickBy/pickBy.test.js b/test/pickBy/pickBy.test.js new file mode 100644 index 000000000..5fc44a26e --- /dev/null +++ b/test/pickBy/pickBy.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const pickBy = require('./pickBy.js'); + +test('Testing pickBy', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof pickBy === 'function', 'pickBy is a Function'); + //t.deepEqual(pickBy(args..), 'Expected'); + //t.equal(pickBy(args..), 'Expected'); + //t.false(pickBy(args..), 'Expected'); + //t.throws(pickBy(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/pipeFunctions/pipeFunctions.js b/test/pipeFunctions/pipeFunctions.js index ea4ac5fb1..46b2ec419 100644 --- a/test/pipeFunctions/pipeFunctions.js +++ b/test/pipeFunctions/pipeFunctions.js @@ -1,2 +1,2 @@ const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args))); - module.exports = pipeFunctions \ No newline at end of file +module.exports = pipeFunctions \ No newline at end of file diff --git a/test/pipeFunctions/pipeFunctions.test.js b/test/pipeFunctions/pipeFunctions.test.js index 61d1285c9..b6255bfad 100644 --- a/test/pipeFunctions/pipeFunctions.test.js +++ b/test/pipeFunctions/pipeFunctions.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const pipeFunctions = require('./pipeFunctions.js'); test('Testing pipeFunctions', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof pipeFunctions === 'function', 'pipeFunctions is a Function'); - //t.deepEqual(pipeFunctions(args..), 'Expected'); - //t.equal(pipeFunctions(args..), 'Expected'); - //t.false(pipeFunctions(args..), 'Expected'); - //t.throws(pipeFunctions(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof pipeFunctions === 'function', 'pipeFunctions is a Function'); + //t.deepEqual(pipeFunctions(args..), 'Expected'); + //t.equal(pipeFunctions(args..), 'Expected'); + //t.false(pipeFunctions(args..), 'Expected'); + //t.throws(pipeFunctions(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/pluralize/pluralize.js b/test/pluralize/pluralize.js index df86b72dd..7e1c477c9 100644 --- a/test/pluralize/pluralize.js +++ b/test/pluralize/pluralize.js @@ -4,4 +4,4 @@ const _pluralize = (num, word, plural = word + 's') => if (typeof val === 'object') return (num, word) => _pluralize(num, word, val[word]); return _pluralize(val, word, plural); }; - module.exports = pluralize \ No newline at end of file +module.exports = pluralize \ No newline at end of file diff --git a/test/pluralize/pluralize.test.js b/test/pluralize/pluralize.test.js index a78180d7a..219f80886 100644 --- a/test/pluralize/pluralize.test.js +++ b/test/pluralize/pluralize.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const pluralize = require('./pluralize.js'); test('Testing pluralize', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof pluralize === 'function', 'pluralize is a Function'); - //t.deepEqual(pluralize(args..), 'Expected'); - //t.equal(pluralize(args..), 'Expected'); - //t.false(pluralize(args..), 'Expected'); - //t.throws(pluralize(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof pluralize === 'function', 'pluralize is a Function'); + //t.deepEqual(pluralize(args..), 'Expected'); + //t.equal(pluralize(args..), 'Expected'); + //t.false(pluralize(args..), 'Expected'); + //t.throws(pluralize(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/powerset/powerset.js b/test/powerset/powerset.js index 0e71c52b1..0804d4c0b 100644 --- a/test/powerset/powerset.js +++ b/test/powerset/powerset.js @@ -1,2 +1,2 @@ const powerset = arr => arr.reduce((a, v) => a.concat(a.map(r => [v].concat(r))), [[]]); - module.exports = powerset \ No newline at end of file +module.exports = powerset \ No newline at end of file diff --git a/test/powerset/powerset.test.js b/test/powerset/powerset.test.js index f0516ca63..a9bf7ba6a 100644 --- a/test/powerset/powerset.test.js +++ b/test/powerset/powerset.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const powerset = require('./powerset.js'); test('Testing powerset', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof powerset === 'function', 'powerset is a Function'); - t.deepEqual(powerset([1, 2]), [[], [1], [2], [2,1]], "Returns the powerset of a given array of numbers."); - //t.deepEqual(powerset(args..), 'Expected'); - //t.equal(powerset(args..), 'Expected'); - //t.false(powerset(args..), 'Expected'); - //t.throws(powerset(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof powerset === 'function', 'powerset is a Function'); + t.deepEqual(powerset([1, 2]), [[], [1], [2], [2,1]], "Returns the powerset of a given array of numbers."); + //t.deepEqual(powerset(args..), 'Expected'); + //t.equal(powerset(args..), 'Expected'); + //t.false(powerset(args..), 'Expected'); + //t.throws(powerset(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/prettyBytes/prettyBytes.js b/test/prettyBytes/prettyBytes.js index dc5d0a5a1..110b723ce 100644 --- a/test/prettyBytes/prettyBytes.js +++ b/test/prettyBytes/prettyBytes.js @@ -5,4 +5,4 @@ const exponent = Math.min(Math.floor(Math.log10(num < 0 ? -num : num) / 3), UNIT const n = Number(((num < 0 ? -num : num) / 1000 ** exponent).toPrecision(precision)); return (num < 0 ? '-' : '') + n + (addSpace ? ' ' : '') + UNITS[exponent]; }; - module.exports = prettyBytes \ No newline at end of file +module.exports = prettyBytes \ No newline at end of file diff --git a/test/prettyBytes/prettyBytes.test.js b/test/prettyBytes/prettyBytes.test.js index 62f974c06..7553e5304 100644 --- a/test/prettyBytes/prettyBytes.test.js +++ b/test/prettyBytes/prettyBytes.test.js @@ -2,16 +2,16 @@ const test = require('tape'); const prettyBytes = require('./prettyBytes.js'); test('Testing prettyBytes', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof prettyBytes === 'function', 'prettyBytes is a Function'); - t.equal(prettyBytes(1000), '1 KB', "Converts a number in bytes to a human-readable string."); - t.equal(prettyBytes(-27145424323.5821, 5), '-27.145 GB', "Converts a number in bytes to a human-readable string."); - t.equal(prettyBytes(123456789, 3, false), '123MB', "Converts a number in bytes to a human-readable string."); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof prettyBytes === 'function', 'prettyBytes is a Function'); + t.equal(prettyBytes(1000), '1 KB', "Converts a number in bytes to a human-readable string."); + t.equal(prettyBytes(-27145424323.5821, 5), '-27.145 GB', "Converts a number in bytes to a human-readable string."); + t.equal(prettyBytes(123456789, 3, false), '123MB', "Converts a number in bytes to a human-readable string."); - //t.deepEqual(prettyBytes(args..), 'Expected'); - //t.equal(prettyBytes(args..), 'Expected'); - //t.false(prettyBytes(args..), 'Expected'); - //t.throws(prettyBytes(args..), 'Expected'); - t.end(); + //t.deepEqual(prettyBytes(args..), 'Expected'); + //t.equal(prettyBytes(args..), 'Expected'); + //t.false(prettyBytes(args..), 'Expected'); + //t.throws(prettyBytes(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/primes/primes.js b/test/primes/primes.js index 3ac251eed..a7a67a86a 100644 --- a/test/primes/primes.js +++ b/test/primes/primes.js @@ -5,4 +5,4 @@ numsTillSqroot = Array.from({ length: sqroot - 1 }).map((x, i) => i + 2); numsTillSqroot.forEach(x => (arr = arr.filter(y => y % x !== 0 || y == x))); return arr; }; - module.exports = primes \ No newline at end of file +module.exports = primes \ No newline at end of file diff --git a/test/primes/primes.test.js b/test/primes/primes.test.js index 0e7c448d9..d64602713 100644 --- a/test/primes/primes.test.js +++ b/test/primes/primes.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const primes = require('./primes.js'); test('Testing primes', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof primes === 'function', 'primes is a Function'); - t.deepEqual(primes(10), [2, 3, 5, 7], "Generates primes up to a given number, using the Sieve of Eratosthenes."); - //t.deepEqual(primes(args..), 'Expected'); - //t.equal(primes(args..), 'Expected'); - //t.false(primes(args..), 'Expected'); - //t.throws(primes(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof primes === 'function', 'primes is a Function'); + t.deepEqual(primes(10), [2, 3, 5, 7], "Generates primes up to a given number, using the Sieve of Eratosthenes."); + //t.deepEqual(primes(args..), 'Expected'); + //t.equal(primes(args..), 'Expected'); + //t.false(primes(args..), 'Expected'); + //t.throws(primes(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/promisify/promisify.js b/test/promisify/promisify.js index a642e309e..c41f99772 100644 --- a/test/promisify/promisify.js +++ b/test/promisify/promisify.js @@ -2,4 +2,4 @@ const promisify = func => (...args) => new Promise((resolve, reject) => func(...args, (err, result) => (err ? reject(err) : resolve(result))) ); - module.exports = promisify \ No newline at end of file +module.exports = promisify \ No newline at end of file diff --git a/test/promisify/promisify.test.js b/test/promisify/promisify.test.js index 0ef7c8465..bba6e071d 100644 --- a/test/promisify/promisify.test.js +++ b/test/promisify/promisify.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const promisify = require('./promisify.js'); test('Testing promisify', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof promisify === 'function', 'promisify is a Function'); - //t.deepEqual(promisify(args..), 'Expected'); - //t.equal(promisify(args..), 'Expected'); - //t.false(promisify(args..), 'Expected'); - //t.throws(promisify(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof promisify === 'function', 'promisify is a Function'); + //t.deepEqual(promisify(args..), 'Expected'); + //t.equal(promisify(args..), 'Expected'); + //t.false(promisify(args..), 'Expected'); + //t.throws(promisify(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/pull/pull.js b/test/pull/pull.js index 08e191399..3b526fd6a 100644 --- a/test/pull/pull.js +++ b/test/pull/pull.js @@ -4,4 +4,4 @@ let pulled = arr.filter((v, i) => !argState.includes(v)); arr.length = 0; pulled.forEach(v => arr.push(v)); }; - module.exports = pull \ No newline at end of file +module.exports = pull \ No newline at end of file diff --git a/test/pull/pull.test.js b/test/pull/pull.test.js index e067e10b6..aa4b11755 100644 --- a/test/pull/pull.test.js +++ b/test/pull/pull.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const pull = require('./pull.js'); test('Testing pull', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof pull === 'function', 'pull is a Function'); - //t.deepEqual(pull(args..), 'Expected'); - //t.equal(pull(args..), 'Expected'); - //t.false(pull(args..), 'Expected'); - //t.throws(pull(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof pull === 'function', 'pull is a Function'); + //t.deepEqual(pull(args..), 'Expected'); + //t.equal(pull(args..), 'Expected'); + //t.false(pull(args..), 'Expected'); + //t.throws(pull(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/pullAtIndex/pullAtIndex.js b/test/pullAtIndex/pullAtIndex.js index 965071754..f85941a9b 100644 --- a/test/pullAtIndex/pullAtIndex.js +++ b/test/pullAtIndex/pullAtIndex.js @@ -7,4 +7,4 @@ arr.length = 0; pulled.forEach(v => arr.push(v)); return removed; }; - module.exports = pullAtIndex \ No newline at end of file +module.exports = pullAtIndex \ No newline at end of file diff --git a/test/pullAtIndex/pullAtIndex.test.js b/test/pullAtIndex/pullAtIndex.test.js index 0fd62bedc..6e243ef04 100644 --- a/test/pullAtIndex/pullAtIndex.test.js +++ b/test/pullAtIndex/pullAtIndex.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const pullAtIndex = require('./pullAtIndex.js'); test('Testing pullAtIndex', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof pullAtIndex === 'function', 'pullAtIndex is a Function'); - //t.deepEqual(pullAtIndex(args..), 'Expected'); - //t.equal(pullAtIndex(args..), 'Expected'); - //t.false(pullAtIndex(args..), 'Expected'); - //t.throws(pullAtIndex(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof pullAtIndex === 'function', 'pullAtIndex is a Function'); + //t.deepEqual(pullAtIndex(args..), 'Expected'); + //t.equal(pullAtIndex(args..), 'Expected'); + //t.false(pullAtIndex(args..), 'Expected'); + //t.throws(pullAtIndex(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/pullAtValue/pullAtValue.js b/test/pullAtValue/pullAtValue.js index db317da51..5750b4b82 100644 --- a/test/pullAtValue/pullAtValue.js +++ b/test/pullAtValue/pullAtValue.js @@ -6,4 +6,4 @@ arr.length = 0; mutateTo.forEach(v => arr.push(v)); return removed; }; - module.exports = pullAtValue \ No newline at end of file +module.exports = pullAtValue \ No newline at end of file diff --git a/test/pullAtValue/pullAtValue.test.js b/test/pullAtValue/pullAtValue.test.js index 10f6b09d0..887020c33 100644 --- a/test/pullAtValue/pullAtValue.test.js +++ b/test/pullAtValue/pullAtValue.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const pullAtValue = require('./pullAtValue.js'); test('Testing pullAtValue', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof pullAtValue === 'function', 'pullAtValue is a Function'); - //t.deepEqual(pullAtValue(args..), 'Expected'); - //t.equal(pullAtValue(args..), 'Expected'); - //t.false(pullAtValue(args..), 'Expected'); - //t.throws(pullAtValue(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof pullAtValue === 'function', 'pullAtValue is a Function'); + //t.deepEqual(pullAtValue(args..), 'Expected'); + //t.equal(pullAtValue(args..), 'Expected'); + //t.false(pullAtValue(args..), 'Expected'); + //t.throws(pullAtValue(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/quickSort/quickSort.js b/test/quickSort/quickSort.js index 06075d924..3b17b2f89 100644 --- a/test/quickSort/quickSort.js +++ b/test/quickSort/quickSort.js @@ -6,4 +6,4 @@ isNaN(n) n, ...quickSort(nums.filter(v => (!desc ? v > n : v <= n)), desc) ]; - module.exports = quickSort \ No newline at end of file +module.exports = quickSort \ No newline at end of file diff --git a/test/quickSort/quickSort.test.js b/test/quickSort/quickSort.test.js index 1252196cd..067b62ce5 100644 --- a/test/quickSort/quickSort.test.js +++ b/test/quickSort/quickSort.test.js @@ -2,11 +2,11 @@ const test = require('tape'); const quickSort = require('./quickSort.js'); test('Testing quickSort', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof quickSort === 'function', 'quickSort is a Function'); - t.deepEqual(quickSort([5, 6, 4, 3, 1, 2]), [1, 2, 3, 4, 5, 6], 'quickSort([5, 6, 4, 3, 1, 2]) returns [1, 2, 3, 4, 5, 6]'); - t.deepEqual(quickSort([-1, 0, -2]), [-2, -1, 0], 'quickSort([-1, 0, -2]) returns [-2, -1, 0]'); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof quickSort === 'function', 'quickSort is a Function'); + t.deepEqual(quickSort([5, 6, 4, 3, 1, 2]), [1, 2, 3, 4, 5, 6], 'quickSort([5, 6, 4, 3, 1, 2]) returns [1, 2, 3, 4, 5, 6]'); + t.deepEqual(quickSort([-1, 0, -2]), [-2, -1, 0], 'quickSort([-1, 0, -2]) returns [-2, -1, 0]'); t.throws(() => quickSort(), 'quickSort() throws an error'); t.throws(() => quickSort(123), 'quickSort(123) throws an error'); t.throws(() => quickSort({ 234: string}), 'quickSort({ 234: string}) throws an error'); @@ -18,5 +18,5 @@ test('Testing quickSort', (t) => { let end = new Date().getTime(); t.true((end - start) < 2000, 'quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]) takes less than 2s to run'); - t.end(); + t.end(); }); \ No newline at end of file diff --git a/test/randomHexColorCode/randomHexColorCode.js b/test/randomHexColorCode/randomHexColorCode.js index ae49ab185..4ff05e1f9 100644 --- a/test/randomHexColorCode/randomHexColorCode.js +++ b/test/randomHexColorCode/randomHexColorCode.js @@ -2,4 +2,4 @@ const randomHexColorCode = () => { let n = ((Math.random() * 0xfffff) | 0).toString(16); return '#' + (n.length !== 6 ? ((Math.random() * 0xf) | 0).toString(16) + n : n); }; - module.exports = randomHexColorCode \ No newline at end of file +module.exports = randomHexColorCode \ No newline at end of file diff --git a/test/randomHexColorCode/randomHexColorCode.test.js b/test/randomHexColorCode/randomHexColorCode.test.js index 39b41b2a7..63f117367 100644 --- a/test/randomHexColorCode/randomHexColorCode.test.js +++ b/test/randomHexColorCode/randomHexColorCode.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const randomHexColorCode = require('./randomHexColorCode.js'); test('Testing randomHexColorCode', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof randomHexColorCode === 'function', 'randomHexColorCode is a Function'); - //t.deepEqual(randomHexColorCode(args..), 'Expected'); - //t.equal(randomHexColorCode(args..), 'Expected'); - //t.false(randomHexColorCode(args..), 'Expected'); - //t.throws(randomHexColorCode(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof randomHexColorCode === 'function', 'randomHexColorCode is a Function'); + //t.deepEqual(randomHexColorCode(args..), 'Expected'); + //t.equal(randomHexColorCode(args..), 'Expected'); + //t.false(randomHexColorCode(args..), 'Expected'); + //t.throws(randomHexColorCode(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/randomIntArrayInRange/randomIntArrayInRange.js b/test/randomIntArrayInRange/randomIntArrayInRange.js index 74c999acc..8136f6f4c 100644 --- a/test/randomIntArrayInRange/randomIntArrayInRange.js +++ b/test/randomIntArrayInRange/randomIntArrayInRange.js @@ -1,3 +1,3 @@ const randomIntArrayInRange = (min, max, n = 1) => Array.from({ length: n }, () => Math.floor(Math.random() * (max - min + 1)) + min); - module.exports = randomIntArrayInRange \ No newline at end of file +module.exports = randomIntArrayInRange \ No newline at end of file diff --git a/test/randomIntArrayInRange/randomIntArrayInRange.test.js b/test/randomIntArrayInRange/randomIntArrayInRange.test.js index 57952ff83..9a7735e44 100644 --- a/test/randomIntArrayInRange/randomIntArrayInRange.test.js +++ b/test/randomIntArrayInRange/randomIntArrayInRange.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const randomIntArrayInRange = require('./randomIntArrayInRange.js'); test('Testing randomIntArrayInRange', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof randomIntArrayInRange === 'function', 'randomIntArrayInRange is a Function'); - //t.deepEqual(randomIntArrayInRange(args..), 'Expected'); - //t.equal(randomIntArrayInRange(args..), 'Expected'); - //t.false(randomIntArrayInRange(args..), 'Expected'); - //t.throws(randomIntArrayInRange(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof randomIntArrayInRange === 'function', 'randomIntArrayInRange is a Function'); + //t.deepEqual(randomIntArrayInRange(args..), 'Expected'); + //t.equal(randomIntArrayInRange(args..), 'Expected'); + //t.false(randomIntArrayInRange(args..), 'Expected'); + //t.throws(randomIntArrayInRange(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/randomIntegerInRange/randomIntegerInRange.js b/test/randomIntegerInRange/randomIntegerInRange.js index 7c6ad38db..2031f2c76 100644 --- a/test/randomIntegerInRange/randomIntegerInRange.js +++ b/test/randomIntegerInRange/randomIntegerInRange.js @@ -1,2 +1,2 @@ const randomIntegerInRange = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; - module.exports = randomIntegerInRange \ No newline at end of file +module.exports = randomIntegerInRange \ No newline at end of file diff --git a/test/randomIntegerInRange/randomIntegerInRange.test.js b/test/randomIntegerInRange/randomIntegerInRange.test.js index 3e821c31f..c294b1208 100644 --- a/test/randomIntegerInRange/randomIntegerInRange.test.js +++ b/test/randomIntegerInRange/randomIntegerInRange.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const randomIntegerInRange = require('./randomIntegerInRange.js'); test('Testing randomIntegerInRange', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof randomIntegerInRange === 'function', 'randomIntegerInRange is a Function'); - //t.deepEqual(randomIntegerInRange(args..), 'Expected'); - //t.equal(randomIntegerInRange(args..), 'Expected'); - //t.false(randomIntegerInRange(args..), 'Expected'); - //t.throws(randomIntegerInRange(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof randomIntegerInRange === 'function', 'randomIntegerInRange is a Function'); + //t.deepEqual(randomIntegerInRange(args..), 'Expected'); + //t.equal(randomIntegerInRange(args..), 'Expected'); + //t.false(randomIntegerInRange(args..), 'Expected'); + //t.throws(randomIntegerInRange(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/randomNumberInRange/randomNumberInRange.js b/test/randomNumberInRange/randomNumberInRange.js index 15a6d3169..db50d7486 100644 --- a/test/randomNumberInRange/randomNumberInRange.js +++ b/test/randomNumberInRange/randomNumberInRange.js @@ -1,2 +1,2 @@ const randomNumberInRange = (min, max) => Math.random() * (max - min) + min; - module.exports = randomNumberInRange \ No newline at end of file +module.exports = randomNumberInRange \ No newline at end of file diff --git a/test/randomNumberInRange/randomNumberInRange.test.js b/test/randomNumberInRange/randomNumberInRange.test.js index 4cc797080..2d3d46bde 100644 --- a/test/randomNumberInRange/randomNumberInRange.test.js +++ b/test/randomNumberInRange/randomNumberInRange.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const randomNumberInRange = require('./randomNumberInRange.js'); test('Testing randomNumberInRange', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof randomNumberInRange === 'function', 'randomNumberInRange is a Function'); - //t.deepEqual(randomNumberInRange(args..), 'Expected'); - //t.equal(randomNumberInRange(args..), 'Expected'); - //t.false(randomNumberInRange(args..), 'Expected'); - //t.throws(randomNumberInRange(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof randomNumberInRange === 'function', 'randomNumberInRange is a Function'); + //t.deepEqual(randomNumberInRange(args..), 'Expected'); + //t.equal(randomNumberInRange(args..), 'Expected'); + //t.false(randomNumberInRange(args..), 'Expected'); + //t.throws(randomNumberInRange(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/readFileLines/readFileLines.js b/test/readFileLines/readFileLines.js index 8e7db19aa..fc286c8eb 100644 --- a/test/readFileLines/readFileLines.js +++ b/test/readFileLines/readFileLines.js @@ -4,4 +4,4 @@ fs .readFileSync(filename) .toString('UTF8') .split('\n'); - module.exports = readFileLines \ No newline at end of file +module.exports = readFileLines \ No newline at end of file diff --git a/test/readFileLines/readFileLines.test.js b/test/readFileLines/readFileLines.test.js index 481741a58..87404799e 100644 --- a/test/readFileLines/readFileLines.test.js +++ b/test/readFileLines/readFileLines.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const readFileLines = require('./readFileLines.js'); test('Testing readFileLines', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof readFileLines === 'function', 'readFileLines is a Function'); - //t.deepEqual(readFileLines(args..), 'Expected'); - //t.equal(readFileLines(args..), 'Expected'); - //t.false(readFileLines(args..), 'Expected'); - //t.throws(readFileLines(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof readFileLines === 'function', 'readFileLines is a Function'); + //t.deepEqual(readFileLines(args..), 'Expected'); + //t.equal(readFileLines(args..), 'Expected'); + //t.false(readFileLines(args..), 'Expected'); + //t.throws(readFileLines(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/redirect/redirect.js b/test/redirect/redirect.js index f7cecfd2b..7959a5f01 100644 --- a/test/redirect/redirect.js +++ b/test/redirect/redirect.js @@ -1,3 +1,3 @@ const redirect = (url, asLink = true) => asLink ? (window.location.href = url) : window.location.replace(url); - module.exports = redirect \ No newline at end of file +module.exports = redirect \ No newline at end of file diff --git a/test/redirect/redirect.test.js b/test/redirect/redirect.test.js index 12dee47dd..0d2f8d4a1 100644 --- a/test/redirect/redirect.test.js +++ b/test/redirect/redirect.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const redirect = require('./redirect.js'); test('Testing redirect', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof redirect === 'function', 'redirect is a Function'); - //t.deepEqual(redirect(args..), 'Expected'); - //t.equal(redirect(args..), 'Expected'); - //t.false(redirect(args..), 'Expected'); - //t.throws(redirect(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof redirect === 'function', 'redirect is a Function'); + //t.deepEqual(redirect(args..), 'Expected'); + //t.equal(redirect(args..), 'Expected'); + //t.false(redirect(args..), 'Expected'); + //t.throws(redirect(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/reduceSuccessive/reduceSuccessive.js b/test/reduceSuccessive/reduceSuccessive.js new file mode 100644 index 000000000..67a9d03b3 --- /dev/null +++ b/test/reduceSuccessive/reduceSuccessive.js @@ -0,0 +1,3 @@ +const reduceSuccessive = (arr, fn, acc) => +arr.reduce((res, val, i, arr) => (res.push(fn(res.slice(-1)[0], val, i, arr)), res), [acc]); +module.exports = reduceSuccessive \ No newline at end of file diff --git a/test/reduceSuccessive/reduceSuccessive.test.js b/test/reduceSuccessive/reduceSuccessive.test.js new file mode 100644 index 000000000..87ec36cdd --- /dev/null +++ b/test/reduceSuccessive/reduceSuccessive.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const reduceSuccessive = require('./reduceSuccessive.js'); + +test('Testing reduceSuccessive', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof reduceSuccessive === 'function', 'reduceSuccessive is a Function'); + //t.deepEqual(reduceSuccessive(args..), 'Expected'); + //t.equal(reduceSuccessive(args..), 'Expected'); + //t.false(reduceSuccessive(args..), 'Expected'); + //t.throws(reduceSuccessive(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/reduceWhich/reduceWhich.js b/test/reduceWhich/reduceWhich.js new file mode 100644 index 000000000..4558ef6b7 --- /dev/null +++ b/test/reduceWhich/reduceWhich.js @@ -0,0 +1,3 @@ +const reduceWhich = (arr, comparator = (a, b) => a - b) => +arr.reduce((a, b) => (comparator(a, b) >= 0 ? b : a)); +module.exports = reduceWhich \ No newline at end of file diff --git a/test/reduceWhich/reduceWhich.test.js b/test/reduceWhich/reduceWhich.test.js new file mode 100644 index 000000000..c5363239b --- /dev/null +++ b/test/reduceWhich/reduceWhich.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const reduceWhich = require('./reduceWhich.js'); + +test('Testing reduceWhich', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof reduceWhich === 'function', 'reduceWhich is a Function'); + //t.deepEqual(reduceWhich(args..), 'Expected'); + //t.equal(reduceWhich(args..), 'Expected'); + //t.false(reduceWhich(args..), 'Expected'); + //t.throws(reduceWhich(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/reducedFilter/reducedFilter.js b/test/reducedFilter/reducedFilter.js index 778c6179f..6e4662f37 100644 --- a/test/reducedFilter/reducedFilter.js +++ b/test/reducedFilter/reducedFilter.js @@ -5,4 +5,4 @@ acc[key] = el[key]; return acc; }, {}) ); - module.exports = reducedFilter \ No newline at end of file +module.exports = reducedFilter \ No newline at end of file diff --git a/test/reducedFilter/reducedFilter.test.js b/test/reducedFilter/reducedFilter.test.js index 29590ad2c..db6dcdc9e 100644 --- a/test/reducedFilter/reducedFilter.test.js +++ b/test/reducedFilter/reducedFilter.test.js @@ -2,25 +2,25 @@ const test = require('tape'); const reducedFilter = require('./reducedFilter.js'); test('Testing reducedFilter', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof reducedFilter === 'function', 'reducedFilter is a Function'); - const data = [ - { - id: 1, - name: 'john', - age: 24 - }, - { - id: 2, - name: 'mike', - age: 50 - } - ]; - t.deepEqual(reducedFilter(data, ['id', 'name'], item => item.age > 24), [{ id: 2, name: 'mike'}], "Filter an array of objects based on a condition while also filtering out unspecified keys."); - //t.deepEqual(reducedFilter(args..), 'Expected'); - //t.equal(reducedFilter(args..), 'Expected'); - //t.false(reducedFilter(args..), 'Expected'); - //t.throws(reducedFilter(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof reducedFilter === 'function', 'reducedFilter is a Function'); + const data = [ + { + id: 1, + name: 'john', + age: 24 + }, + { + id: 2, + name: 'mike', + age: 50 + } + ]; + t.deepEqual(reducedFilter(data, ['id', 'name'], item => item.age > 24), [{ id: 2, name: 'mike'}], "Filter an array of objects based on a condition while also filtering out unspecified keys."); + //t.deepEqual(reducedFilter(args..), 'Expected'); + //t.equal(reducedFilter(args..), 'Expected'); + //t.false(reducedFilter(args..), 'Expected'); + //t.throws(reducedFilter(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/remove/remove.js b/test/remove/remove.js index 75afb01bc..9132f4290 100644 --- a/test/remove/remove.js +++ b/test/remove/remove.js @@ -5,4 +5,4 @@ arr.splice(arr.indexOf(val), 1); return acc.concat(val); }, []) : []; - module.exports = remove \ No newline at end of file +module.exports = remove \ No newline at end of file diff --git a/test/remove/remove.test.js b/test/remove/remove.test.js index f0b658901..0300c8c2a 100644 --- a/test/remove/remove.test.js +++ b/test/remove/remove.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const remove = require('./remove.js'); test('Testing remove', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof remove === 'function', 'remove is a Function'); - t.deepEqual(remove([1, 2, 3, 4], n => n % 2 == 0), [2, 4], "Removes elements from an array for which the given function returns false"); - //t.deepEqual(remove(args..), 'Expected'); - //t.equal(remove(args..), 'Expected'); - //t.false(remove(args..), 'Expected'); - //t.throws(remove(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof remove === 'function', 'remove is a Function'); + t.deepEqual(remove([1, 2, 3, 4], n => n % 2 == 0), [2, 4], "Removes elements from an array for which the given function returns false"); + //t.deepEqual(remove(args..), 'Expected'); + //t.equal(remove(args..), 'Expected'); + //t.false(remove(args..), 'Expected'); + //t.throws(remove(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/removeVowels/removeVowels.js b/test/removeVowels/removeVowels.js index 770f01b90..8f9fd62bf 100644 --- a/test/removeVowels/removeVowels.js +++ b/test/removeVowels/removeVowels.js @@ -1,2 +1,2 @@ const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi,repl); - module.exports = removeVowels \ No newline at end of file +module.exports = removeVowels \ No newline at end of file diff --git a/test/removeVowels/removeVowels.test.js b/test/removeVowels/removeVowels.test.js index be9566c24..67a187869 100644 --- a/test/removeVowels/removeVowels.test.js +++ b/test/removeVowels/removeVowels.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const removeVowels = require('./removeVowels.js'); test('Testing removeVowels', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof removeVowels === 'function', 'removeVowels is a Function'); - //t.deepEqual(removeVowels(args..), 'Expected'); - //t.equal(removeVowels(args..), 'Expected'); - //t.false(removeVowels(args..), 'Expected'); - //t.throws(removeVowels(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof removeVowels === 'function', 'removeVowels is a Function'); + //t.deepEqual(removeVowels(args..), 'Expected'); + //t.equal(removeVowels(args..), 'Expected'); + //t.false(removeVowels(args..), 'Expected'); + //t.throws(removeVowels(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/reverseString/reverseString.js b/test/reverseString/reverseString.js index b5abbf1d5..1b98ef6c1 100644 --- a/test/reverseString/reverseString.js +++ b/test/reverseString/reverseString.js @@ -1,2 +1,2 @@ const reverseString = str => [...str].reverse().join(''); - module.exports = reverseString \ No newline at end of file +module.exports = reverseString \ No newline at end of file diff --git a/test/reverseString/reverseString.test.js b/test/reverseString/reverseString.test.js index aa930ef15..7aeca53df 100644 --- a/test/reverseString/reverseString.test.js +++ b/test/reverseString/reverseString.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const reverseString = require('./reverseString.js'); test('Testing reverseString', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof reverseString === 'function', 'reverseString is a Function'); - t.equal(reverseString('foobar'), 'raboof', "Reverses a string."); - //t.deepEqual(reverseString(args..), 'Expected'); - //t.equal(reverseString(args..), 'Expected'); - //t.false(reverseString(args..), 'Expected'); - //t.throws(reverseString(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof reverseString === 'function', 'reverseString is a Function'); + t.equal(reverseString('foobar'), 'raboof', "Reverses a string."); + //t.deepEqual(reverseString(args..), 'Expected'); + //t.equal(reverseString(args..), 'Expected'); + //t.false(reverseString(args..), 'Expected'); + //t.throws(reverseString(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/round/round.js b/test/round/round.js index 778e00441..2f86eb4d9 100644 --- a/test/round/round.js +++ b/test/round/round.js @@ -1,2 +1,2 @@ const round = (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`); - module.exports = round \ No newline at end of file +module.exports = round \ No newline at end of file diff --git a/test/round/round.test.js b/test/round/round.test.js index 47aab350f..7af718c04 100644 --- a/test/round/round.test.js +++ b/test/round/round.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const round = require('./round.js'); test('Testing round', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof round === 'function', 'round is a Function'); - t.equal(round(1.005, 2), 1.01, "Rounds a number to a specified amount of digits."); - //t.equal(round(args..), 'Expected'); - //t.false(round(args..), 'Expected'); - //t.throws(round(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof round === 'function', 'round is a Function'); + t.equal(round(1.005, 2), 1.01, "Rounds a number to a specified amount of digits."); + //t.equal(round(args..), 'Expected'); + //t.false(round(args..), 'Expected'); + //t.throws(round(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/runAsync/runAsync.js b/test/runAsync/runAsync.js index 1778fde70..c5cc4c1a3 100644 --- a/test/runAsync/runAsync.js +++ b/test/runAsync/runAsync.js @@ -14,4 +14,4 @@ rej(err), worker.terminate(); }; }); }; - module.exports = runAsync \ No newline at end of file +module.exports = runAsync \ No newline at end of file diff --git a/test/runAsync/runAsync.test.js b/test/runAsync/runAsync.test.js index 5d6a24c56..76e7b11c0 100644 --- a/test/runAsync/runAsync.test.js +++ b/test/runAsync/runAsync.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const runAsync = require('./runAsync.js'); test('Testing runAsync', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof runAsync === 'function', 'runAsync is a Function'); - //t.deepEqual(runAsync(args..), 'Expected'); - //t.equal(runAsync(args..), 'Expected'); - //t.false(runAsync(args..), 'Expected'); - //t.throws(runAsync(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof runAsync === 'function', 'runAsync is a Function'); + //t.deepEqual(runAsync(args..), 'Expected'); + //t.equal(runAsync(args..), 'Expected'); + //t.false(runAsync(args..), 'Expected'); + //t.throws(runAsync(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/runPromisesInSeries/runPromisesInSeries.js b/test/runPromisesInSeries/runPromisesInSeries.js index ced59e23e..8ce9536f2 100644 --- a/test/runPromisesInSeries/runPromisesInSeries.js +++ b/test/runPromisesInSeries/runPromisesInSeries.js @@ -1,2 +1,2 @@ const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.resolve()); - module.exports = runPromisesInSeries \ No newline at end of file +module.exports = runPromisesInSeries \ No newline at end of file diff --git a/test/runPromisesInSeries/runPromisesInSeries.test.js b/test/runPromisesInSeries/runPromisesInSeries.test.js index 78a7b13e9..9011ddaf5 100644 --- a/test/runPromisesInSeries/runPromisesInSeries.test.js +++ b/test/runPromisesInSeries/runPromisesInSeries.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const runPromisesInSeries = require('./runPromisesInSeries.js'); test('Testing runPromisesInSeries', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof runPromisesInSeries === 'function', 'runPromisesInSeries is a Function'); - //t.deepEqual(runPromisesInSeries(args..), 'Expected'); - //t.equal(runPromisesInSeries(args..), 'Expected'); - //t.false(runPromisesInSeries(args..), 'Expected'); - //t.throws(runPromisesInSeries(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof runPromisesInSeries === 'function', 'runPromisesInSeries is a Function'); + //t.deepEqual(runPromisesInSeries(args..), 'Expected'); + //t.equal(runPromisesInSeries(args..), 'Expected'); + //t.false(runPromisesInSeries(args..), 'Expected'); + //t.throws(runPromisesInSeries(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/sample/sample.js b/test/sample/sample.js index 992949efe..b230d5b89 100644 --- a/test/sample/sample.js +++ b/test/sample/sample.js @@ -1,2 +1,2 @@ const sample = arr => arr[Math.floor(Math.random() * arr.length)]; - module.exports = sample \ No newline at end of file +module.exports = sample \ No newline at end of file diff --git a/test/sample/sample.test.js b/test/sample/sample.test.js index 6f2e5ee2c..47f575acb 100644 --- a/test/sample/sample.test.js +++ b/test/sample/sample.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const sample = require('./sample.js'); test('Testing sample', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof sample === 'function', 'sample is a Function'); - //t.deepEqual(sample(args..), 'Expected'); - //t.equal(sample(args..), 'Expected'); - //t.false(sample(args..), 'Expected'); - //t.throws(sample(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof sample === 'function', 'sample is a Function'); + //t.deepEqual(sample(args..), 'Expected'); + //t.equal(sample(args..), 'Expected'); + //t.false(sample(args..), 'Expected'); + //t.throws(sample(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/sampleSize/sampleSize.js b/test/sampleSize/sampleSize.js index 231810f54..dba6acd68 100644 --- a/test/sampleSize/sampleSize.js +++ b/test/sampleSize/sampleSize.js @@ -6,4 +6,4 @@ const i = Math.floor(Math.random() * m--); } return arr.slice(0, n); }; - module.exports = sampleSize \ No newline at end of file +module.exports = sampleSize \ No newline at end of file diff --git a/test/sampleSize/sampleSize.test.js b/test/sampleSize/sampleSize.test.js index 5527d8304..1ac15836e 100644 --- a/test/sampleSize/sampleSize.test.js +++ b/test/sampleSize/sampleSize.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const sampleSize = require('./sampleSize.js'); test('Testing sampleSize', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof sampleSize === 'function', 'sampleSize is a Function'); - //t.deepEqual(sampleSize(args..), 'Expected'); - //t.equal(sampleSize(args..), 'Expected'); - //t.false(sampleSize(args..), 'Expected'); - //t.throws(sampleSize(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof sampleSize === 'function', 'sampleSize is a Function'); + //t.deepEqual(sampleSize(args..), 'Expected'); + //t.equal(sampleSize(args..), 'Expected'); + //t.false(sampleSize(args..), 'Expected'); + //t.throws(sampleSize(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/scrollToTop/scrollToTop.js b/test/scrollToTop/scrollToTop.js index d45b2a44e..b99155274 100644 --- a/test/scrollToTop/scrollToTop.js +++ b/test/scrollToTop/scrollToTop.js @@ -5,4 +5,4 @@ window.requestAnimationFrame(scrollToTop); window.scrollTo(0, c - c / 8); } }; - module.exports = scrollToTop \ No newline at end of file +module.exports = scrollToTop \ No newline at end of file diff --git a/test/scrollToTop/scrollToTop.test.js b/test/scrollToTop/scrollToTop.test.js index acc2ff3a2..082b4fc4e 100644 --- a/test/scrollToTop/scrollToTop.test.js +++ b/test/scrollToTop/scrollToTop.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const scrollToTop = require('./scrollToTop.js'); test('Testing scrollToTop', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof scrollToTop === 'function', 'scrollToTop is a Function'); - //t.deepEqual(scrollToTop(args..), 'Expected'); - //t.equal(scrollToTop(args..), 'Expected'); - //t.false(scrollToTop(args..), 'Expected'); - //t.throws(scrollToTop(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof scrollToTop === 'function', 'scrollToTop is a Function'); + //t.deepEqual(scrollToTop(args..), 'Expected'); + //t.equal(scrollToTop(args..), 'Expected'); + //t.false(scrollToTop(args..), 'Expected'); + //t.throws(scrollToTop(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/sdbm/sdbm.js b/test/sdbm/sdbm.js index ff9012a7f..43f750617 100644 --- a/test/sdbm/sdbm.js +++ b/test/sdbm/sdbm.js @@ -6,4 +6,4 @@ return arr.reduce( 0 ); }; - module.exports = sdbm \ No newline at end of file +module.exports = sdbm \ No newline at end of file diff --git a/test/sdbm/sdbm.test.js b/test/sdbm/sdbm.test.js index c0247bccf..8152041bb 100644 --- a/test/sdbm/sdbm.test.js +++ b/test/sdbm/sdbm.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const sdbm = require('./sdbm.js'); test('Testing sdbm', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof sdbm === 'function', 'sdbm is a Function'); - t.equal(sdbm('name'), -3521204949, "Hashes the input string into a whole number."); - //t.deepEqual(sdbm(args..), 'Expected'); - //t.equal(sdbm(args..), 'Expected'); - //t.false(sdbm(args..), 'Expected'); - //t.throws(sdbm(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof sdbm === 'function', 'sdbm is a Function'); + t.equal(sdbm('name'), -3521204949, "Hashes the input string into a whole number."); + //t.deepEqual(sdbm(args..), 'Expected'); + //t.equal(sdbm(args..), 'Expected'); + //t.false(sdbm(args..), 'Expected'); + //t.throws(sdbm(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/serializeCookie/serializeCookie.js b/test/serializeCookie/serializeCookie.js index ed4f462a7..62c174699 100644 --- a/test/serializeCookie/serializeCookie.js +++ b/test/serializeCookie/serializeCookie.js @@ -1,2 +1,2 @@ const serializeCookie = (name, val) => `${encodeURIComponent(name)}=${encodeURIComponent(val)}`; - module.exports = serializeCookie \ No newline at end of file +module.exports = serializeCookie \ No newline at end of file diff --git a/test/serializeCookie/serializeCookie.test.js b/test/serializeCookie/serializeCookie.test.js index 7e4e3a88a..526f353ec 100644 --- a/test/serializeCookie/serializeCookie.test.js +++ b/test/serializeCookie/serializeCookie.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const serializeCookie = require('./serializeCookie.js'); test('Testing serializeCookie', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof serializeCookie === 'function', 'serializeCookie is a Function'); - //t.deepEqual(serializeCookie(args..), 'Expected'); - //t.equal(serializeCookie(args..), 'Expected'); - //t.false(serializeCookie(args..), 'Expected'); - //t.throws(serializeCookie(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof serializeCookie === 'function', 'serializeCookie is a Function'); + //t.deepEqual(serializeCookie(args..), 'Expected'); + //t.equal(serializeCookie(args..), 'Expected'); + //t.false(serializeCookie(args..), 'Expected'); + //t.throws(serializeCookie(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/setStyle/setStyle.js b/test/setStyle/setStyle.js index 71db449eb..49574a009 100644 --- a/test/setStyle/setStyle.js +++ b/test/setStyle/setStyle.js @@ -1,2 +1,2 @@ const setStyle = (el, ruleName, val) => (el.style[ruleName] = val); - module.exports = setStyle \ No newline at end of file +module.exports = setStyle \ No newline at end of file diff --git a/test/setStyle/setStyle.test.js b/test/setStyle/setStyle.test.js index 9ccaea787..796ab1316 100644 --- a/test/setStyle/setStyle.test.js +++ b/test/setStyle/setStyle.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const setStyle = require('./setStyle.js'); test('Testing setStyle', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof setStyle === 'function', 'setStyle is a Function'); - //t.deepEqual(setStyle(args..), 'Expected'); - //t.equal(setStyle(args..), 'Expected'); - //t.false(setStyle(args..), 'Expected'); - //t.throws(setStyle(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof setStyle === 'function', 'setStyle is a Function'); + //t.deepEqual(setStyle(args..), 'Expected'); + //t.equal(setStyle(args..), 'Expected'); + //t.false(setStyle(args..), 'Expected'); + //t.throws(setStyle(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/shallowClone/shallowClone.js b/test/shallowClone/shallowClone.js index 8247d3f8e..a502e8a17 100644 --- a/test/shallowClone/shallowClone.js +++ b/test/shallowClone/shallowClone.js @@ -1,2 +1,2 @@ const shallowClone = obj => Object.assign({}, obj); - module.exports = shallowClone \ No newline at end of file +module.exports = shallowClone \ No newline at end of file diff --git a/test/shallowClone/shallowClone.test.js b/test/shallowClone/shallowClone.test.js index b62b37998..71223569b 100644 --- a/test/shallowClone/shallowClone.test.js +++ b/test/shallowClone/shallowClone.test.js @@ -2,12 +2,16 @@ const test = require('tape'); const shallowClone = require('./shallowClone.js'); test('Testing shallowClone', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof shallowClone === 'function', 'shallowClone is a Function'); - //t.deepEqual(shallowClone(args..), 'Expected'); - //t.equal(shallowClone(args..), 'Expected'); - //t.false(shallowClone(args..), 'Expected'); - //t.throws(shallowClone(args..), 'Expected'); - t.end(); -}); \ No newline at end of file + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof shallowClone === 'function', 'shallowClone is a Function'); + const a = { foo: 'bar', obj: { a: 1, b: 2 } }; + const b = shallowClone(a); + t.notEqual(a, b, 'Shallow cloning works'); + t.equal(a.obj, b.obj, 'Does not clone deeply'); + //t.deepEqual(shallowClone(args..), 'Expected'); + //t.equal(shallowClone(args..), 'Expected'); + //t.false(shallowClone(args..), 'Expected'); + //t.throws(shallowClone(args..), 'Expected'); + t.end(); +}); diff --git a/test/show/show.js b/test/show/show.js index db22eab4f..f48b74226 100644 --- a/test/show/show.js +++ b/test/show/show.js @@ -1,2 +1,2 @@ const show = (...el) => [...el].forEach(e => (e.style.display = '')); - module.exports = show \ No newline at end of file +module.exports = show \ No newline at end of file diff --git a/test/show/show.test.js b/test/show/show.test.js index f8e81e7a5..06cf5e26e 100644 --- a/test/show/show.test.js +++ b/test/show/show.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const show = require('./show.js'); test('Testing show', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof show === 'function', 'show is a Function'); - //t.deepEqual(show(args..), 'Expected'); - //t.equal(show(args..), 'Expected'); - //t.false(show(args..), 'Expected'); - //t.throws(show(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof show === 'function', 'show is a Function'); + //t.deepEqual(show(args..), 'Expected'); + //t.equal(show(args..), 'Expected'); + //t.false(show(args..), 'Expected'); + //t.throws(show(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/shuffle/shuffle.js b/test/shuffle/shuffle.js index d2d3980ee..6f17df997 100644 --- a/test/shuffle/shuffle.js +++ b/test/shuffle/shuffle.js @@ -6,4 +6,4 @@ const i = Math.floor(Math.random() * m--); } return arr; }; - module.exports = shuffle \ No newline at end of file +module.exports = shuffle \ No newline at end of file diff --git a/test/shuffle/shuffle.test.js b/test/shuffle/shuffle.test.js index ebb1921f6..2d19478fa 100644 --- a/test/shuffle/shuffle.test.js +++ b/test/shuffle/shuffle.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const shuffle = require('./shuffle.js'); test('Testing shuffle', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof shuffle === 'function', 'shuffle is a Function'); - //t.deepEqual(shuffle(args..), 'Expected'); - //t.equal(shuffle(args..), 'Expected'); - //t.false(shuffle(args..), 'Expected'); - //t.throws(shuffle(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof shuffle === 'function', 'shuffle is a Function'); + //t.deepEqual(shuffle(args..), 'Expected'); + //t.equal(shuffle(args..), 'Expected'); + //t.false(shuffle(args..), 'Expected'); + //t.throws(shuffle(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/similarity/similarity.js b/test/similarity/similarity.js index 3a3cc41e5..e1c53bfa6 100644 --- a/test/similarity/similarity.js +++ b/test/similarity/similarity.js @@ -1,2 +1,2 @@ const similarity = (arr, values) => arr.filter(v => values.includes(v)); - module.exports = similarity \ No newline at end of file +module.exports = similarity \ No newline at end of file diff --git a/test/similarity/similarity.test.js b/test/similarity/similarity.test.js index fb6fbca4f..b82022707 100644 --- a/test/similarity/similarity.test.js +++ b/test/similarity/similarity.test.js @@ -2,11 +2,11 @@ const test = require('tape'); const similarity = require('./similarity.js'); test('Testing similarity', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof similarity === 'function', 'similarity is a Function'); - t.deepEqual(similarity([1, 2, 3], [1, 2, 4]), [1, 2], "Returns an array of elements that appear in both arrays."); //t.equal(similarity(args..), 'Expected'); - //t.false(similarity(args..), 'Expected'); - //t.throws(similarity(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof similarity === 'function', 'similarity is a Function'); + t.deepEqual(similarity([1, 2, 3], [1, 2, 4]), [1, 2], "Returns an array of elements that appear in both arrays."); //t.equal(similarity(args..), 'Expected'); + //t.false(similarity(args..), 'Expected'); + //t.throws(similarity(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/size/size.js b/test/size/size.js index 639c8351f..55bb37d0d 100644 --- a/test/size/size.js +++ b/test/size/size.js @@ -4,4 +4,4 @@ Array.isArray(val) : val && typeof val === 'object' ? val.size || val.length || Object.keys(val).length : typeof val === 'string' ? new Blob([val]).size : 0; - module.exports = size \ No newline at end of file +module.exports = size \ No newline at end of file diff --git a/test/size/size.test.js b/test/size/size.test.js index 467e842a2..5c8410b23 100644 --- a/test/size/size.test.js +++ b/test/size/size.test.js @@ -2,16 +2,16 @@ const test = require('tape'); const size = require('./size.js'); test('Testing size', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof size === 'function', 'size is a Function'); - t.equal(size([1, 2, 3, 4, 5]), 5, "Get size of arrays, objects or strings."); - // t.equal(size('size'), 4, "Get size of arrays, objects or strings."); DOESN'T WORK IN NODE ENV - t.equal(size({ one: 1, two: 2, three: 3 }), 3, "Get size of arrays, objects or strings."); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof size === 'function', 'size is a Function'); + t.equal(size([1, 2, 3, 4, 5]), 5, "Get size of arrays, objects or strings."); + // t.equal(size('size'), 4, "Get size of arrays, objects or strings."); DOESN'T WORK IN NODE ENV + t.equal(size({ one: 1, two: 2, three: 3 }), 3, "Get size of arrays, objects or strings."); - //t.deepEqual(size(args..), 'Expected'); - //t.equal(size(args..), 'Expected'); - //t.false(size(args..), 'Expected'); - //t.throws(size(args..), 'Expected'); - t.end(); + //t.deepEqual(size(args..), 'Expected'); + //t.equal(size(args..), 'Expected'); + //t.false(size(args..), 'Expected'); + //t.throws(size(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/sleep/sleep.js b/test/sleep/sleep.js index 4cfc9e189..ac53ad307 100644 --- a/test/sleep/sleep.js +++ b/test/sleep/sleep.js @@ -1,2 +1,2 @@ const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); - module.exports = sleep \ No newline at end of file +module.exports = sleep \ No newline at end of file diff --git a/test/sleep/sleep.test.js b/test/sleep/sleep.test.js index 7b56c9c77..8d5388924 100644 --- a/test/sleep/sleep.test.js +++ b/test/sleep/sleep.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const sleep = require('./sleep.js'); test('Testing sleep', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof sleep === 'function', 'sleep is a Function'); - //t.deepEqual(sleep(args..), 'Expected'); - //t.equal(sleep(args..), 'Expected'); - //t.false(sleep(args..), 'Expected'); - //t.throws(sleep(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof sleep === 'function', 'sleep is a Function'); + //t.deepEqual(sleep(args..), 'Expected'); + //t.equal(sleep(args..), 'Expected'); + //t.false(sleep(args..), 'Expected'); + //t.throws(sleep(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/solveRPN/solveRPN.js b/test/solveRPN/solveRPN.js index 43e3d509a..57e7ecc41 100644 --- a/test/solveRPN/solveRPN.js +++ b/test/solveRPN/solveRPN.js @@ -26,4 +26,4 @@ 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 \ No newline at end of file +module.exports = solveRPN \ No newline at end of file diff --git a/test/solveRPN/solveRPN.test.js b/test/solveRPN/solveRPN.test.js index aa288918d..78cea6cdf 100644 --- a/test/solveRPN/solveRPN.test.js +++ b/test/solveRPN/solveRPN.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const solveRPN = require('./solveRPN.js'); test('Testing solveRPN', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof solveRPN === 'function', 'solveRPN is a Function'); - //t.deepEqual(solveRPN(args..), 'Expected'); - //t.equal(solveRPN(args..), 'Expected'); - //t.false(solveRPN(args..), 'Expected'); - //t.throws(solveRPN(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof solveRPN === 'function', 'solveRPN is a Function'); + //t.deepEqual(solveRPN(args..), 'Expected'); + //t.equal(solveRPN(args..), 'Expected'); + //t.false(solveRPN(args..), 'Expected'); + //t.throws(solveRPN(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/sortCharactersInString/sortCharactersInString.js b/test/sortCharactersInString/sortCharactersInString.js index 74e6f2811..b8bcbef82 100644 --- a/test/sortCharactersInString/sortCharactersInString.js +++ b/test/sortCharactersInString/sortCharactersInString.js @@ -1,2 +1,2 @@ const sortCharactersInString = str => [...str].sort((a, b) => a.localeCompare(b)).join(''); - module.exports = sortCharactersInString \ No newline at end of file +module.exports = sortCharactersInString \ No newline at end of file diff --git a/test/sortCharactersInString/sortCharactersInString.test.js b/test/sortCharactersInString/sortCharactersInString.test.js index 685393e6f..25fc97bd8 100644 --- a/test/sortCharactersInString/sortCharactersInString.test.js +++ b/test/sortCharactersInString/sortCharactersInString.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const sortCharactersInString = require('./sortCharactersInString.js'); test('Testing sortCharactersInString', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof sortCharactersInString === 'function', 'sortCharactersInString is a Function'); - t.equal(sortCharactersInString('cabbage'), 'aabbceg', "Alphabetically sorts the characters in a string."); - //t.deepEqual(sortCharactersInString(args..), 'Expected'); - //t.equal(sortCharactersInString(args..), 'Expected'); - //t.false(sortCharactersInString(args..), 'Expected'); - //t.throws(sortCharactersInString(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof sortCharactersInString === 'function', 'sortCharactersInString is a Function'); + t.equal(sortCharactersInString('cabbage'), 'aabbceg', "Alphabetically sorts the characters in a string."); + //t.deepEqual(sortCharactersInString(args..), 'Expected'); + //t.equal(sortCharactersInString(args..), 'Expected'); + //t.false(sortCharactersInString(args..), 'Expected'); + //t.throws(sortCharactersInString(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/sortedIndex/sortedIndex.js b/test/sortedIndex/sortedIndex.js index b4eb24061..c181d53ca 100644 --- a/test/sortedIndex/sortedIndex.js +++ b/test/sortedIndex/sortedIndex.js @@ -3,4 +3,4 @@ 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 \ No newline at end of file +module.exports = sortedIndex \ No newline at end of file diff --git a/test/sortedIndex/sortedIndex.test.js b/test/sortedIndex/sortedIndex.test.js index f81cec793..c60ba058f 100644 --- a/test/sortedIndex/sortedIndex.test.js +++ b/test/sortedIndex/sortedIndex.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const sortedIndex = require('./sortedIndex.js'); test('Testing sortedIndex', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof sortedIndex === 'function', 'sortedIndex is a Function'); - t.equal(sortedIndex([5, 3, 2, 1], 4), 1, "Returns the lowest index at which value should be inserted into array in order to maintain its sort order."); - t.equal(sortedIndex([30, 50], 40), 1, "Returns the lowest index at which value should be inserted into array in order to maintain its sort order."); - //t.deepEqual(sortedIndex(args..), 'Expected'); - //t.equal(sortedIndex(args..), 'Expected'); - //t.false(sortedIndex(args..), 'Expected'); - //t.throws(sortedIndex(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof sortedIndex === 'function', 'sortedIndex is a Function'); + t.equal(sortedIndex([5, 3, 2, 1], 4), 1, "Returns the lowest index at which value should be inserted into array in order to maintain its sort order."); + t.equal(sortedIndex([30, 50], 40), 1, "Returns the lowest index at which value should be inserted into array in order to maintain its sort order."); + //t.deepEqual(sortedIndex(args..), 'Expected'); + //t.equal(sortedIndex(args..), 'Expected'); + //t.false(sortedIndex(args..), 'Expected'); + //t.throws(sortedIndex(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/sortedLastIndex/sortedLastIndex.js b/test/sortedLastIndex/sortedLastIndex.js new file mode 100644 index 000000000..eaee796a5 --- /dev/null +++ b/test/sortedLastIndex/sortedLastIndex.js @@ -0,0 +1,9 @@ +const sortedLastIndex = (arr, n) => { +const isDescending = arr[0] > arr[arr.length - 1]; +const index = arr +.map((val, i) => [i, val]) +.filter(el => (isDescending ? n >= el[1] : n >= el[1])) +.slice(-1)[0][0]; +return index === -1 ? arr.length : index; +}; +module.exports = sortedLastIndex \ No newline at end of file diff --git a/test/sortedLastIndex/sortedLastIndex.test.js b/test/sortedLastIndex/sortedLastIndex.test.js new file mode 100644 index 000000000..f51f3b732 --- /dev/null +++ b/test/sortedLastIndex/sortedLastIndex.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const sortedLastIndex = require('./sortedLastIndex.js'); + +test('Testing sortedLastIndex', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof sortedLastIndex === 'function', 'sortedLastIndex is a Function'); + //t.deepEqual(sortedLastIndex(args..), 'Expected'); + //t.equal(sortedLastIndex(args..), 'Expected'); + //t.false(sortedLastIndex(args..), 'Expected'); + //t.throws(sortedLastIndex(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/speechSynthesis/speechSynthesis.js b/test/speechSynthesis/speechSynthesis.js index eff6d4ce7..633cb5e41 100644 --- a/test/speechSynthesis/speechSynthesis.js +++ b/test/speechSynthesis/speechSynthesis.js @@ -3,4 +3,4 @@ const msg = new SpeechSynthesisUtterance(message); msg.voice = window.speechSynthesis.getVoices()[0]; window.speechSynthesis.speak(msg); }; - module.exports = speechSynthesis \ No newline at end of file +module.exports = speechSynthesis \ No newline at end of file diff --git a/test/speechSynthesis/speechSynthesis.test.js b/test/speechSynthesis/speechSynthesis.test.js index 81b4547f4..16d2f891f 100644 --- a/test/speechSynthesis/speechSynthesis.test.js +++ b/test/speechSynthesis/speechSynthesis.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const speechSynthesis = require('./speechSynthesis.js'); test('Testing speechSynthesis', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof speechSynthesis === 'function', 'speechSynthesis is a Function'); - //t.deepEqual(speechSynthesis(args..), 'Expected'); - //t.equal(speechSynthesis(args..), 'Expected'); - //t.false(speechSynthesis(args..), 'Expected'); - //t.throws(speechSynthesis(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof speechSynthesis === 'function', 'speechSynthesis is a Function'); + //t.deepEqual(speechSynthesis(args..), 'Expected'); + //t.equal(speechSynthesis(args..), 'Expected'); + //t.false(speechSynthesis(args..), 'Expected'); + //t.throws(speechSynthesis(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/splitLines/splitLines.js b/test/splitLines/splitLines.js index b112b6e0f..2d675dbc6 100644 --- a/test/splitLines/splitLines.js +++ b/test/splitLines/splitLines.js @@ -1,2 +1,2 @@ const splitLines = str => str.split(/\r?\n/); - module.exports = splitLines \ No newline at end of file +module.exports = splitLines \ No newline at end of file diff --git a/test/splitLines/splitLines.test.js b/test/splitLines/splitLines.test.js index e10b8b4b3..7d03fd581 100644 --- a/test/splitLines/splitLines.test.js +++ b/test/splitLines/splitLines.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const splitLines = require('./splitLines.js'); test('Testing splitLines', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof splitLines === 'function', 'splitLines is a Function'); - t.deepEqual(splitLines('This\nis a\nmultiline\nstring.\n'), ['This', 'is a', 'multiline', 'string.' , ''], "Splits a multiline string into an array of lines."); - //t.deepEqual(splitLines(args..), 'Expected'); - //t.equal(splitLines(args..), 'Expected'); - //t.false(splitLines(args..), 'Expected'); - //t.throws(splitLines(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof splitLines === 'function', 'splitLines is a Function'); + t.deepEqual(splitLines('This\nis a\nmultiline\nstring.\n'), ['This', 'is a', 'multiline', 'string.' , ''], "Splits a multiline string into an array of lines."); + //t.deepEqual(splitLines(args..), 'Expected'); + //t.equal(splitLines(args..), 'Expected'); + //t.false(splitLines(args..), 'Expected'); + //t.throws(splitLines(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/spreadOver/spreadOver.js b/test/spreadOver/spreadOver.js index 0048bff7f..5f2274140 100644 --- a/test/spreadOver/spreadOver.js +++ b/test/spreadOver/spreadOver.js @@ -1,2 +1,2 @@ const spreadOver = fn => argsArr => fn(...argsArr); - module.exports = spreadOver \ No newline at end of file +module.exports = spreadOver \ No newline at end of file diff --git a/test/spreadOver/spreadOver.test.js b/test/spreadOver/spreadOver.test.js index ebb019d9b..d294b4f52 100644 --- a/test/spreadOver/spreadOver.test.js +++ b/test/spreadOver/spreadOver.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const spreadOver = require('./spreadOver.js'); test('Testing spreadOver', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof spreadOver === 'function', 'spreadOver is a Function'); - const arrayMax = spreadOver(Math.max); - t.equal(arrayMax([1, 2, 3]), 3, "Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function."); - //t.deepEqual(spreadOver(args..), 'Expected'); - //t.equal(spreadOver(args..), 'Expected'); - //t.false(spreadOver(args..), 'Expected'); - //t.throws(spreadOver(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof spreadOver === 'function', 'spreadOver is a Function'); + const arrayMax = spreadOver(Math.max); + t.equal(arrayMax([1, 2, 3]), 3, "Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function."); + //t.deepEqual(spreadOver(args..), 'Expected'); + //t.equal(spreadOver(args..), 'Expected'); + //t.false(spreadOver(args..), 'Expected'); + //t.throws(spreadOver(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/standardDeviation/standardDeviation.js b/test/standardDeviation/standardDeviation.js index e9a033e68..249125b88 100644 --- a/test/standardDeviation/standardDeviation.js +++ b/test/standardDeviation/standardDeviation.js @@ -5,4 +5,4 @@ arr.reduce((acc, val) => acc.concat((val - mean) ** 2), []).reduce((acc, val) => (arr.length - (usePopulation ? 0 : 1)) ); }; - module.exports = standardDeviation \ No newline at end of file +module.exports = standardDeviation \ No newline at end of file diff --git a/test/standardDeviation/standardDeviation.test.js b/test/standardDeviation/standardDeviation.test.js index fd0ffef6f..ad43efb90 100644 --- a/test/standardDeviation/standardDeviation.test.js +++ b/test/standardDeviation/standardDeviation.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const standardDeviation = require('./standardDeviation.js'); test('Testing standardDeviation', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof standardDeviation === 'function', 'standardDeviation is a Function'); - t.equal(standardDeviation([10, 2, 38, 23, 38, 23, 21]), 13.284434142114991, "Returns the standard deviation of an array of numbers"); - t.equal(standardDeviation([10, 2, 38, 23, 38, 23, 21], true), 12.29899614287479, "Returns the standard deviation of an array of numbers"); - //t.deepEqual(standardDeviation(args..), 'Expected'); - //t.equal(standardDeviation(args..), 'Expected'); - //t.false(standardDeviation(args..), 'Expected'); - //t.throws(standardDeviation(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof standardDeviation === 'function', 'standardDeviation is a Function'); + t.equal(standardDeviation([10, 2, 38, 23, 38, 23, 21]), 13.284434142114991, "Returns the standard deviation of an array of numbers"); + t.equal(standardDeviation([10, 2, 38, 23, 38, 23, 21], true), 12.29899614287479, "Returns the standard deviation of an array of numbers"); + //t.deepEqual(standardDeviation(args..), 'Expected'); + //t.equal(standardDeviation(args..), 'Expected'); + //t.false(standardDeviation(args..), 'Expected'); + //t.throws(standardDeviation(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/sum/sum.js b/test/sum/sum.js index 22db1d186..27ba3fe25 100644 --- a/test/sum/sum.js +++ b/test/sum/sum.js @@ -1,2 +1,2 @@ const sum = (...arr) => [...arr].reduce((acc, val) => acc + val, 0); - module.exports = sum \ No newline at end of file +module.exports = sum \ No newline at end of file diff --git a/test/sum/sum.test.js b/test/sum/sum.test.js index 476caad87..7abf88f6f 100644 --- a/test/sum/sum.test.js +++ b/test/sum/sum.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const sum = require('./sum.js'); test('Testing sum', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof sum === 'function', 'sum is a Function'); - t.equal(sum(...[1, 2, 3, 4]), 10, "Returns the sum of two or more numbers/arrays."); - //t.deepEqual(sum(args..), 'Expected'); - //t.equal(sum(args..), 'Expected'); - //t.false(sum(args..), 'Expected'); - //t.throws(sum(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof sum === 'function', 'sum is a Function'); + t.equal(sum(...[1, 2, 3, 4]), 10, "Returns the sum of two or more numbers/arrays."); + //t.deepEqual(sum(args..), 'Expected'); + //t.equal(sum(args..), 'Expected'); + //t.false(sum(args..), 'Expected'); + //t.throws(sum(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/sumBy/sumBy.js b/test/sumBy/sumBy.js index 4c499baf5..c78200a47 100644 --- a/test/sumBy/sumBy.js +++ b/test/sumBy/sumBy.js @@ -1,3 +1,3 @@ const sumBy = (arr, fn) => arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0); - module.exports = sumBy \ No newline at end of file +module.exports = sumBy \ No newline at end of file diff --git a/test/sumBy/sumBy.test.js b/test/sumBy/sumBy.test.js index 23c6140fe..7d2660dec 100644 --- a/test/sumBy/sumBy.test.js +++ b/test/sumBy/sumBy.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const sumBy = require('./sumBy.js'); test('Testing sumBy', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof sumBy === 'function', 'sumBy is a Function'); - //t.deepEqual(sumBy(args..), 'Expected'); - //t.equal(sumBy(args..), 'Expected'); - //t.false(sumBy(args..), 'Expected'); - //t.throws(sumBy(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof sumBy === 'function', 'sumBy is a Function'); + //t.deepEqual(sumBy(args..), 'Expected'); + //t.equal(sumBy(args..), 'Expected'); + //t.false(sumBy(args..), 'Expected'); + //t.throws(sumBy(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/sumPower/sumPower.js b/test/sumPower/sumPower.js index 51b80ab57..a739bad0c 100644 --- a/test/sumPower/sumPower.js +++ b/test/sumPower/sumPower.js @@ -3,4 +3,4 @@ Array(end + 1 - start) .fill(0) .map((x, i) => (i + start) ** power) .reduce((a, b) => a + b, 0); - module.exports = sumPower \ No newline at end of file +module.exports = sumPower \ No newline at end of file diff --git a/test/sumPower/sumPower.test.js b/test/sumPower/sumPower.test.js index 2c5828339..44cb6d64f 100644 --- a/test/sumPower/sumPower.test.js +++ b/test/sumPower/sumPower.test.js @@ -2,15 +2,15 @@ const test = require('tape'); const sumPower = require('./sumPower.js'); test('Testing sumPower', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof sumPower === 'function', 'sumPower is a Function'); - t.equal(sumPower(10), 385, "Returns the sum of the powers of all the numbers from start to end"); - t.equal(sumPower(10, 3), 3025, "Returns the sum of the powers of all the numbers from start to end"); - t.equal(sumPower(10, 3, 5), 2925, "Returns the sum of the powers of all the numbers from start to end"); - //t.deepEqual(sumPower(args..), 'Expected'); - //t.equal(sumPower(args..), 'Expected'); - //t.false(sumPower(args..), 'Expected'); - //t.throws(sumPower(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof sumPower === 'function', 'sumPower is a Function'); + t.equal(sumPower(10), 385, "Returns the sum of the powers of all the numbers from start to end"); + t.equal(sumPower(10, 3), 3025, "Returns the sum of the powers of all the numbers from start to end"); + t.equal(sumPower(10, 3, 5), 2925, "Returns the sum of the powers of all the numbers from start to end"); + //t.deepEqual(sumPower(args..), 'Expected'); + //t.equal(sumPower(args..), 'Expected'); + //t.false(sumPower(args..), 'Expected'); + //t.throws(sumPower(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/symmetricDifference/symmetricDifference.js b/test/symmetricDifference/symmetricDifference.js index 862698500..5f2f4fe9a 100644 --- a/test/symmetricDifference/symmetricDifference.js +++ b/test/symmetricDifference/symmetricDifference.js @@ -3,4 +3,4 @@ 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 \ No newline at end of file +module.exports = symmetricDifference \ No newline at end of file diff --git a/test/symmetricDifference/symmetricDifference.test.js b/test/symmetricDifference/symmetricDifference.test.js index 2c8d7544b..1ceeba195 100644 --- a/test/symmetricDifference/symmetricDifference.test.js +++ b/test/symmetricDifference/symmetricDifference.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const symmetricDifference = require('./symmetricDifference.js'); test('Testing symmetricDifference', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof symmetricDifference === 'function', 'symmetricDifference is a Function'); - t.deepEqual(symmetricDifference([1, 2, 3], [1, 2, 4]), [3, 4], "Returns the symmetric difference between two arrays."); - //t.deepEqual(symmetricDifference(args..), 'Expected'); - //t.equal(symmetricDifference(args..), 'Expected'); - //t.false(symmetricDifference(args..), 'Expected'); - //t.throws(symmetricDifference(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof symmetricDifference === 'function', 'symmetricDifference is a Function'); + t.deepEqual(symmetricDifference([1, 2, 3], [1, 2, 4]), [3, 4], "Returns the symmetric difference between two arrays."); + //t.deepEqual(symmetricDifference(args..), 'Expected'); + //t.equal(symmetricDifference(args..), 'Expected'); + //t.false(symmetricDifference(args..), 'Expected'); + //t.throws(symmetricDifference(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/symmetricDifferenceBy/symmetricDifferenceBy.js b/test/symmetricDifferenceBy/symmetricDifferenceBy.js new file mode 100644 index 000000000..5ffe62578 --- /dev/null +++ b/test/symmetricDifferenceBy/symmetricDifferenceBy.js @@ -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 \ No newline at end of file diff --git a/test/symmetricDifferenceBy/symmetricDifferenceBy.test.js b/test/symmetricDifferenceBy/symmetricDifferenceBy.test.js new file mode 100644 index 000000000..306e3d5e8 --- /dev/null +++ b/test/symmetricDifferenceBy/symmetricDifferenceBy.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const symmetricDifferenceBy = require('./symmetricDifferenceBy.js'); + +test('Testing symmetricDifferenceBy', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof symmetricDifferenceBy === 'function', 'symmetricDifferenceBy is a Function'); + //t.deepEqual(symmetricDifferenceBy(args..), 'Expected'); + //t.equal(symmetricDifferenceBy(args..), 'Expected'); + //t.false(symmetricDifferenceBy(args..), 'Expected'); + //t.throws(symmetricDifferenceBy(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/symmetricDifferenceWith/symmetricDifferenceWith.js b/test/symmetricDifferenceWith/symmetricDifferenceWith.js new file mode 100644 index 000000000..0f58ea86a --- /dev/null +++ b/test/symmetricDifferenceWith/symmetricDifferenceWith.js @@ -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 \ No newline at end of file diff --git a/test/symmetricDifferenceWith/symmetricDifferenceWith.test.js b/test/symmetricDifferenceWith/symmetricDifferenceWith.test.js new file mode 100644 index 000000000..c2afcddd8 --- /dev/null +++ b/test/symmetricDifferenceWith/symmetricDifferenceWith.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const symmetricDifferenceWith = require('./symmetricDifferenceWith.js'); + +test('Testing symmetricDifferenceWith', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof symmetricDifferenceWith === 'function', 'symmetricDifferenceWith is a Function'); + //t.deepEqual(symmetricDifferenceWith(args..), 'Expected'); + //t.equal(symmetricDifferenceWith(args..), 'Expected'); + //t.false(symmetricDifferenceWith(args..), 'Expected'); + //t.throws(symmetricDifferenceWith(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/tail/tail.js b/test/tail/tail.js index 4a32f24a3..a13eb8836 100644 --- a/test/tail/tail.js +++ b/test/tail/tail.js @@ -1,2 +1,2 @@ const tail = arr => (arr.length > 1 ? arr.slice(1) : arr); - module.exports = tail \ No newline at end of file +module.exports = tail \ No newline at end of file diff --git a/test/tail/tail.test.js b/test/tail/tail.test.js index 499a1bc3a..6eb499139 100644 --- a/test/tail/tail.test.js +++ b/test/tail/tail.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const tail = require('./tail.js'); test('Testing tail', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof tail === 'function', 'tail is a Function'); - t.deepEqual(tail([1, 2, 3]), [2, 3], "Returns tail"); - t.deepEqual(tail([1]), [1], "Returns tail"); - //t.deepEqual(tail(args..), 'Expected'); - //t.equal(tail(args..), 'Expected'); - //t.false(tail(args..), 'Expected'); - //t.throws(tail(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof tail === 'function', 'tail is a Function'); + t.deepEqual(tail([1, 2, 3]), [2, 3], "Returns tail"); + t.deepEqual(tail([1]), [1], "Returns tail"); + //t.deepEqual(tail(args..), 'Expected'); + //t.equal(tail(args..), 'Expected'); + //t.false(tail(args..), 'Expected'); + //t.throws(tail(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/take/take.js b/test/take/take.js index a5b82b446..4bb5d6a19 100644 --- a/test/take/take.js +++ b/test/take/take.js @@ -1,2 +1,2 @@ const take = (arr, n = 1) => arr.slice(0, n); - module.exports = take \ No newline at end of file +module.exports = take \ No newline at end of file diff --git a/test/take/take.test.js b/test/take/take.test.js index 57a549c64..2d2aed44c 100644 --- a/test/take/take.test.js +++ b/test/take/take.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const take = require('./take.js'); test('Testing take', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof take === 'function', 'take is a Function'); - t.deepEqual(take([1, 2, 3], 5), [1, 2, 3], "Returns an array with n elements removed from the beginning.") - t.deepEqual(take([1, 2, 3], 0), [], "Returns an array with n elements removed from the beginning.") - //t.deepEqual(take(args..), 'Expected'); - //t.equal(take(args..), 'Expected'); - //t.false(take(args..), 'Expected'); - //t.throws(take(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof take === 'function', 'take is a Function'); + t.deepEqual(take([1, 2, 3], 5), [1, 2, 3], "Returns an array with n elements removed from the beginning.") + t.deepEqual(take([1, 2, 3], 0), [], "Returns an array with n elements removed from the beginning.") + //t.deepEqual(take(args..), 'Expected'); + //t.equal(take(args..), 'Expected'); + //t.false(take(args..), 'Expected'); + //t.throws(take(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/takeRight/takeRight.js b/test/takeRight/takeRight.js index b5bcef3d6..14bf346c8 100644 --- a/test/takeRight/takeRight.js +++ b/test/takeRight/takeRight.js @@ -1,2 +1,2 @@ const takeRight = (arr, n = 1) => arr.slice(arr.length - n, arr.length); - module.exports = takeRight \ No newline at end of file +module.exports = takeRight \ No newline at end of file diff --git a/test/takeRight/takeRight.test.js b/test/takeRight/takeRight.test.js index 5a8231fe7..a7625862b 100644 --- a/test/takeRight/takeRight.test.js +++ b/test/takeRight/takeRight.test.js @@ -2,14 +2,14 @@ const test = require('tape'); const takeRight = require('./takeRight.js'); test('Testing takeRight', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof takeRight === 'function', 'takeRight is a Function'); - t.deepEqual(takeRight([1, 2, 3], 2), [2, 3], "Returns an array with n elements removed from the end"); - t.deepEqual(takeRight([1, 2, 3]), [3], "Returns an array with n elements removed from the end"); - //t.deepEqual(takeRight(args..), 'Expected'); - //t.equal(takeRight(args..), 'Expected'); - //t.false(takeRight(args..), 'Expected'); - //t.throws(takeRight(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof takeRight === 'function', 'takeRight is a Function'); + t.deepEqual(takeRight([1, 2, 3], 2), [2, 3], "Returns an array with n elements removed from the end"); + t.deepEqual(takeRight([1, 2, 3]), [3], "Returns an array with n elements removed from the end"); + //t.deepEqual(takeRight(args..), 'Expected'); + //t.equal(takeRight(args..), 'Expected'); + //t.false(takeRight(args..), 'Expected'); + //t.throws(takeRight(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/testlog b/test/testlog index 7441a3f3e..956f11cdb 100644 --- a/test/testlog +++ b/test/testlog @@ -1,4 +1,4 @@ -Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) +Test log for: Thu Jan 25 2018 20:12:57 GMT+0000 (UTC) > 30-seconds-of-code@0.0.1 test /home/travis/build/Chalarangelo/30-seconds-of-code > tape test/**/*.test.js | tap-spec @@ -44,9 +44,15 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ arrayToHtmlList is a Function + Testing ary + + ✔ ary is a Function + Testing atob ✔ atob is a Function + ✔ atob("Zm9vYmFy") equals "foobar" + ✔ atob("Z") returns "" Testing average @@ -66,11 +72,21 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) Testing averageBy ✔ averageBy is a Function + ✔ Produces the right result with a function + ✔ Produces the right result with a property name Testing binarySearch ✔ binarySearch is a Function + Testing bind + + ✔ bind is a Function + + Testing bindKey + + ✔ bindKey is a Function + Testing bottomVisible ✔ bottomVisible is a Function @@ -78,6 +94,7 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) Testing btoa ✔ btoa is a Function + ✔ btoa("foobar") equals "Zm9vYmFy" Testing byteSize @@ -98,6 +115,15 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ capitalizeEveryWord is a Function ✔ Capitalizes the first letter of every word in a string + Testing castArray + + ✔ castArray is a Function + ✔ Works for single values + ✔ Works for arrays with one value + ✔ Works for arrays with multiple value + ✔ Works for strings + ✔ Works for objects + Testing chainAsync ✔ chainAsync is a Function @@ -128,6 +154,7 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) Testing cloneRegExp ✔ cloneRegExp is a Function + ✔ Clones regular expressions properly Testing coalesce @@ -161,6 +188,11 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ compose is a Function ✔ Performs right-to-left function composition + Testing composeRight + + ✔ composeRight is a Function + ✔ Performs left-to-right function composition + Testing copyToClipboard ✔ copyToClipboard is a Function @@ -200,15 +232,29 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ decapitalize is a Function + Testing deepClone + + ✔ deepClone is a Function + ✔ Shallow cloning works + ✔ Deep cloning works + Testing deepFlatten ✔ deepFlatten is a Function ✔ Deep flattens an array + Testing defaults + + ✔ defaults is a Function + Testing defer ✔ defer is a Function + Testing delay + + ✔ delay is a Function + Testing detectDeviceType ✔ detectDeviceType is a Function @@ -218,6 +264,10 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ difference is a Function ✔ Returns the difference between two arrays + Testing differenceBy + + ✔ differenceBy is a Function + Testing differenceWith ✔ differenceWith is a Function @@ -316,10 +366,22 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ filterNonUnique is a Function ✔ Filters out the non-unique values in an array + Testing findKey + + ✔ findKey is a Function + Testing findLast ✔ findLast is a Function + Testing findLastIndex + + ✔ findLastIndex is a Function + + Testing findLastKey + + ✔ findLastKey is a Function + Testing flatten ✔ flatten is a Function @@ -334,6 +396,14 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ forEachRight is a Function + Testing forOwn + + ✔ forOwn is a Function + + Testing forOwnRight + + ✔ forOwnRight is a Function + Testing formatDuration ✔ formatDuration is a Function @@ -513,14 +583,39 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ intersection is a Function ✔ Returns a list of elements that exist in both arrays + Testing intersectionBy + + ✔ intersectionBy is a Function + + Testing intersectionWith + + ✔ intersectionWith is a Function + Testing invertKeyValues ✔ invertKeyValues is a Function - ✔ Inverts the key-value pairs of an object + ✔ invertKeyValues({ a: 1, b: 2, c: 1 }) returns { 1: [ 'a', 'c' ], 2: [ 'b' ] } + ✔ invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value) returns { group1: [ 'a', 'c' ], group2: [ 'b' ] } Testing is ✔ is is a Function + ✔ Works for arrays with data + ✔ Works for empty arrays + ✔ Works for arrays, not objects + ✔ Works for objects + ✔ Works for maps + ✔ Works for regular expressions + ✔ Works for sets + ✔ Works for weak maps + ✔ Works for weak sets + ✔ Works for strings - returns false for primitive + ✔ Works for strings - returns true when using constructor + ✔ Works for numbers - returns false for primitive + ✔ Works for numbers - returns true when using constructor + ✔ Works for booleans - returns false for primitive + ✔ Works for booleans - returns true when using constructor + ✔ Works for functions Testing isAbsoluteURL @@ -558,6 +653,10 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ isDivisible is a Function ✔ The number 6 is divisible by 3 + Testing isEmpty + + ✔ isEmpty is a Function + Testing isEven ✔ isEven is a Function @@ -605,6 +704,14 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ isObject({ a:1 }) is a object ✔ isObject(true) is not a object + Testing isObjectLike + + ✔ isObjectLike is a Function + + Testing isPlainObject + + ✔ isPlainObject is a Function + Testing isPrime ✔ isPrime is a Function @@ -753,9 +860,19 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ Replaces all but the last num of characters with the specified mask character ✔ Replaces all but the last num of characters with the specified mask character + Testing matches + + ✔ matches is a Function + + Testing matchesWith + + ✔ matchesWith is a Function + Testing maxBy ✔ maxBy is a Function + ✔ Produces the right result with a function + ✔ Produces the right result with a property name Testing maxN @@ -780,6 +897,8 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) Testing minBy ✔ minBy is a Function + ✔ Produces the right result with a function + ✔ Produces the right result with a property name Testing minN @@ -792,6 +911,10 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ negate is a Function ✔ Negates a predicate function + Testing nthArg + + ✔ nthArg is a Function + Testing nthElement ✔ nthElement is a Function @@ -816,6 +939,14 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ off is a Function + Testing omit + + ✔ omit is a Function + + Testing omitBy + + ✔ omitBy is a Function + Testing on ✔ on is a Function @@ -834,6 +965,10 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ Returns a sorted array of objects ordered by properties and orders. ✔ Returns a sorted array of objects ordered by properties and orders. + Testing over + + ✔ over is a Function + Testing palindrome ✔ palindrome is a Function @@ -844,6 +979,14 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ parseCookie is a Function + Testing partial + + ✔ partial is a Function + + Testing partialRight + + ✔ partialRight is a Function + Testing partition ✔ partition is a Function @@ -859,6 +1002,10 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ pick is a Function ✔ Picks the key-value pairs corresponding to the given keys from an object. + Testing pickBy + + ✔ pickBy is a Function + Testing pipeFunctions ✔ pipeFunctions is a Function @@ -936,6 +1083,14 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ redirect is a Function + Testing reduceSuccessive + + ✔ reduceSuccessive is a Function + + Testing reduceWhich + + ✔ reduceWhich is a Function + Testing reducedFilter ✔ reducedFilter is a Function @@ -996,6 +1151,8 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) Testing shallowClone ✔ shallowClone is a Function + ✔ Shallow cloning works + ✔ Does not clone deeply Testing show @@ -1035,6 +1192,10 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ Returns the lowest index at which value should be inserted into array in order to maintain its sort order. ✔ Returns the lowest index at which value should be inserted into array in order to maintain its sort order. + Testing sortedLastIndex + + ✔ sortedLastIndex is a Function + Testing speechSynthesis ✔ speechSynthesis is a Function @@ -1076,6 +1237,14 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ symmetricDifference is a Function ✔ Returns the symmetric difference between two arrays. + Testing symmetricDifferenceBy + + ✔ symmetricDifferenceBy is a Function + + Testing symmetricDifferenceWith + + ✔ symmetricDifferenceWith is a Function + Testing tail ✔ tail is a Function @@ -1098,6 +1267,10 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ timeTaken is a Function + Testing times + + ✔ times is a Function + Testing toCamelCase ✔ toCamelCase is a Function @@ -1166,16 +1339,32 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ truthCheckCollection is a Function ✔ second argument is truthy on all elements of a collection + Testing unary + + ✔ unary is a Function + Testing unescapeHTML ✔ unescapeHTML is a Function ✔ Unescapes escaped HTML characters. + Testing unfold + + ✔ unfold is a Function + Testing union ✔ union is a Function ✔ Returns every element that exists in any of the two arrays once + Testing unionBy + + ✔ unionBy is a Function + + Testing unionWith + + ✔ unionWith is a Function + Testing uniqueElements ✔ uniqueElements is a Function @@ -1185,6 +1374,17 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ untildify is a Function + Testing unzip + + ✔ unzip is a Function + ✔ unzip([['a', 1, true], ['b', 2, false]]) equals [['a', 'b'], [1, 2], [true, false]] + ✔ unzip([['a', 1, true], ['b', 2]]) equals [['a', 'b'], [1, 2], [true]] + + Testing unzipWith + + ✔ unzipWith is a Function + ✔ unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0)) equals [3, 30, 300] + Testing validateNumber ✔ validateNumber is a Function @@ -1227,6 +1427,11 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ words([]) throws a error ✔ words(1234) throws a error + Testing xProd + + ✔ xProd is a Function + ✔ xProd([1, 2], ['a', 'b']) returns [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] + Testing yesNo ✔ yesNo is a Function @@ -1268,9 +1473,13 @@ Test log for: Thu Jan 18 2018 20:09:23 GMT+0000 (UTC) ✔ zipObject(string) throws an error ✔ zipObject(test, string) throws an error + Testing zipWith - total: 556 - passing: 556 - duration: 307ms + ✔ zipWith is a Function + + + total: 639 + passing: 639 + duration: 487ms diff --git a/test/timeTaken/timeTaken.js b/test/timeTaken/timeTaken.js index ae31b01a2..59d0def76 100644 --- a/test/timeTaken/timeTaken.js +++ b/test/timeTaken/timeTaken.js @@ -4,4 +4,4 @@ const r = callback(); console.timeEnd('timeTaken'); return r; }; - module.exports = timeTaken \ No newline at end of file +module.exports = timeTaken \ No newline at end of file diff --git a/test/timeTaken/timeTaken.test.js b/test/timeTaken/timeTaken.test.js index 7e5201970..45d8aa0eb 100644 --- a/test/timeTaken/timeTaken.test.js +++ b/test/timeTaken/timeTaken.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const timeTaken = require('./timeTaken.js'); test('Testing timeTaken', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof timeTaken === 'function', 'timeTaken is a Function'); - //t.deepEqual(timeTaken(args..), 'Expected'); - //t.equal(timeTaken(args..), 'Expected'); - //t.false(timeTaken(args..), 'Expected'); - //t.throws(timeTaken(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof timeTaken === 'function', 'timeTaken is a Function'); + //t.deepEqual(timeTaken(args..), 'Expected'); + //t.equal(timeTaken(args..), 'Expected'); + //t.false(timeTaken(args..), 'Expected'); + //t.throws(timeTaken(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/times/times.js b/test/times/times.js new file mode 100644 index 000000000..8866d35b4 --- /dev/null +++ b/test/times/times.js @@ -0,0 +1,5 @@ +const times = (n, fn, context = undefined) => { +let i = 0; +while (fn.call(context, i) !== false && ++i < n) {} +}; +module.exports = times \ No newline at end of file diff --git a/test/times/times.test.js b/test/times/times.test.js new file mode 100644 index 000000000..4e94c7d20 --- /dev/null +++ b/test/times/times.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const times = require('./times.js'); + +test('Testing times', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof times === 'function', 'times is a Function'); + //t.deepEqual(times(args..), 'Expected'); + //t.equal(times(args..), 'Expected'); + //t.false(times(args..), 'Expected'); + //t.throws(times(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/toCamelCase/toCamelCase.js b/test/toCamelCase/toCamelCase.js index 44ee52a34..93d2098c1 100644 --- a/test/toCamelCase/toCamelCase.js +++ b/test/toCamelCase/toCamelCase.js @@ -7,4 +7,4 @@ str .join(''); return s.slice(0, 1).toLowerCase() + s.slice(1); }; - module.exports = toCamelCase \ No newline at end of file +module.exports = toCamelCase \ No newline at end of file diff --git a/test/toCamelCase/toCamelCase.test.js b/test/toCamelCase/toCamelCase.test.js index 8746a2bf3..b41794011 100644 --- a/test/toCamelCase/toCamelCase.test.js +++ b/test/toCamelCase/toCamelCase.test.js @@ -2,16 +2,16 @@ const test = require('tape'); const toCamelCase = require('./toCamelCase.js'); test('Testing toCamelCase', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof toCamelCase === 'function', 'toCamelCase is a Function'); - t.equal(toCamelCase('some_database_field_name'), 'someDatabaseFieldName', "Converts a string to camelCase"); - t.equal(toCamelCase('Some label that needs to be camelized'), 'someLabelThatNeedsToBeCamelized', "Converts a string to camelCase"); - t.equal(toCamelCase('some-javascript-property'), 'someJavascriptProperty', "Converts a string to camelCase"); - t.equal(toCamelCase('some-mixed_string with spaces_underscores-and-hyphens'), 'someMixedStringWithSpacesUnderscoresAndHyphens', "Converts a string to camelCase"); - //t.deepEqual(toCamelCase(args..), 'Expected'); - //t.equal(toCamelCase(args..), 'Expected'); - //t.false(toCamelCase(args..), 'Expected'); - //t.throws(toCamelCase(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof toCamelCase === 'function', 'toCamelCase is a Function'); + t.equal(toCamelCase('some_database_field_name'), 'someDatabaseFieldName', "Converts a string to camelCase"); + t.equal(toCamelCase('Some label that needs to be camelized'), 'someLabelThatNeedsToBeCamelized', "Converts a string to camelCase"); + t.equal(toCamelCase('some-javascript-property'), 'someJavascriptProperty', "Converts a string to camelCase"); + t.equal(toCamelCase('some-mixed_string with spaces_underscores-and-hyphens'), 'someMixedStringWithSpacesUnderscoresAndHyphens', "Converts a string to camelCase"); + //t.deepEqual(toCamelCase(args..), 'Expected'); + //t.equal(toCamelCase(args..), 'Expected'); + //t.false(toCamelCase(args..), 'Expected'); + //t.throws(toCamelCase(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/toDecimalMark/toDecimalMark.js b/test/toDecimalMark/toDecimalMark.js index e7de2e7d9..68b31c094 100644 --- a/test/toDecimalMark/toDecimalMark.js +++ b/test/toDecimalMark/toDecimalMark.js @@ -1,2 +1,2 @@ const toDecimalMark = num => num.toLocaleString('en-US'); - module.exports = toDecimalMark \ No newline at end of file +module.exports = toDecimalMark \ No newline at end of file diff --git a/test/toDecimalMark/toDecimalMark.test.js b/test/toDecimalMark/toDecimalMark.test.js index d1234065f..0da36d864 100644 --- a/test/toDecimalMark/toDecimalMark.test.js +++ b/test/toDecimalMark/toDecimalMark.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const toDecimalMark = require('./toDecimalMark.js'); test('Testing toDecimalMark', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof toDecimalMark === 'function', 'toDecimalMark is a Function'); - t.equal(toDecimalMark(12305030388.9087), "12,305,030,388.909", "convert a float-point arithmetic to the Decimal mark form"); - //t.deepEqual(toDecimalMark(args..), 'Expected'); - //t.equal(toDecimalMark(args..), 'Expected'); - //t.false(toDecimalMark(args..), 'Expected'); - //t.throws(toDecimalMark(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof toDecimalMark === 'function', 'toDecimalMark is a Function'); + t.equal(toDecimalMark(12305030388.9087), "12,305,030,388.909", "convert a float-point arithmetic to the Decimal mark form"); + //t.deepEqual(toDecimalMark(args..), 'Expected'); + //t.equal(toDecimalMark(args..), 'Expected'); + //t.false(toDecimalMark(args..), 'Expected'); + //t.throws(toDecimalMark(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/toKebabCase/toKebabCase.js b/test/toKebabCase/toKebabCase.js index 2b313a66d..7a8fef0f6 100644 --- a/test/toKebabCase/toKebabCase.js +++ b/test/toKebabCase/toKebabCase.js @@ -4,4 +4,4 @@ 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 \ No newline at end of file +module.exports = toKebabCase \ No newline at end of file diff --git a/test/toKebabCase/toKebabCase.test.js b/test/toKebabCase/toKebabCase.test.js index 01bd40b2c..fe305e2b2 100644 --- a/test/toKebabCase/toKebabCase.test.js +++ b/test/toKebabCase/toKebabCase.test.js @@ -2,16 +2,16 @@ const test = require('tape'); const toKebabCase = require('./toKebabCase.js'); test('Testing toKebabCase', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof toKebabCase === 'function', 'toKebabCase is a Function'); - t.equal(toKebabCase('camelCase'), 'camel-case', "string converts to snake case"); - t.equal(toKebabCase('some text'), 'some-text', "string converts to snake case"); - t.equal(toKebabCase('some-mixed-string With spaces-underscores-and-hyphens'), 'some-mixed-string-with-spaces-underscores-and-hyphens', "string converts to snake case"); - t.equal(toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'), 'i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html', "string converts to snake case"); - //t.deepEqual(toKebabCase(args..), 'Expected'); - //t.equal(toKebabCase(args..), 'Expected'); - //t.false(toKebabCase(args..), 'Expected'); - //t.throws(toKebabCase(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof toKebabCase === 'function', 'toKebabCase is a Function'); + t.equal(toKebabCase('camelCase'), 'camel-case', "string converts to snake case"); + t.equal(toKebabCase('some text'), 'some-text', "string converts to snake case"); + t.equal(toKebabCase('some-mixed-string With spaces-underscores-and-hyphens'), 'some-mixed-string-with-spaces-underscores-and-hyphens', "string converts to snake case"); + t.equal(toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'), 'i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html', "string converts to snake case"); + //t.deepEqual(toKebabCase(args..), 'Expected'); + //t.equal(toKebabCase(args..), 'Expected'); + //t.false(toKebabCase(args..), 'Expected'); + //t.throws(toKebabCase(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/toOrdinalSuffix/toOrdinalSuffix.js b/test/toOrdinalSuffix/toOrdinalSuffix.js index 6afa22b31..0f3d9b25d 100644 --- a/test/toOrdinalSuffix/toOrdinalSuffix.js +++ b/test/toOrdinalSuffix/toOrdinalSuffix.js @@ -8,4 +8,4 @@ return oPattern.includes(digits[0]) && !tPattern.includes(digits[1]) ? int + ordinals[digits[0] - 1] : int + ordinals[3]; }; - module.exports = toOrdinalSuffix \ No newline at end of file +module.exports = toOrdinalSuffix \ No newline at end of file diff --git a/test/toOrdinalSuffix/toOrdinalSuffix.test.js b/test/toOrdinalSuffix/toOrdinalSuffix.test.js index d33dead0a..a58c7cf64 100644 --- a/test/toOrdinalSuffix/toOrdinalSuffix.test.js +++ b/test/toOrdinalSuffix/toOrdinalSuffix.test.js @@ -2,17 +2,17 @@ const test = require('tape'); const toOrdinalSuffix = require('./toOrdinalSuffix.js'); test('Testing toOrdinalSuffix', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof toOrdinalSuffix === 'function', 'toOrdinalSuffix is a Function'); - t.equal(toOrdinalSuffix('123'), '123rd', 'Adds an ordinal suffix to a number'); - t.equal(toOrdinalSuffix(5), '5th', 'Adds an ordinal suffix to a number'); - t.equal(toOrdinalSuffix(1), '1st', 'Adds an ordinal suffix to a number'); - t.equal(toOrdinalSuffix(0), '0th', 'Adds an ordinal suffix to a number'); - // t.equal(toOrdinalSuffix(), ,); - //t.deepEqual(toOrdinalSuffix(args..), 'Expected'); - //t.equal(toOrdinalSuffix(args..), 'Expected'); - //t.false(toOrdinalSuffix(args..), 'Expected'); - //t.throws(toOrdinalSuffix(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof toOrdinalSuffix === 'function', 'toOrdinalSuffix is a Function'); + t.equal(toOrdinalSuffix('123'), '123rd', 'Adds an ordinal suffix to a number'); + t.equal(toOrdinalSuffix(5), '5th', 'Adds an ordinal suffix to a number'); + t.equal(toOrdinalSuffix(1), '1st', 'Adds an ordinal suffix to a number'); + t.equal(toOrdinalSuffix(0), '0th', 'Adds an ordinal suffix to a number'); + // t.equal(toOrdinalSuffix(), ,); + //t.deepEqual(toOrdinalSuffix(args..), 'Expected'); + //t.equal(toOrdinalSuffix(args..), 'Expected'); + //t.false(toOrdinalSuffix(args..), 'Expected'); + //t.throws(toOrdinalSuffix(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/toSafeInteger/toSafeInteger.js b/test/toSafeInteger/toSafeInteger.js index 166e465a4..b34b0b0b7 100644 --- a/test/toSafeInteger/toSafeInteger.js +++ b/test/toSafeInteger/toSafeInteger.js @@ -1,3 +1,3 @@ const toSafeInteger = num => Math.round(Math.max(Math.min(num, Number.MAX_SAFE_INTEGER), Number.MIN_SAFE_INTEGER)); - module.exports = toSafeInteger \ No newline at end of file +module.exports = toSafeInteger \ No newline at end of file diff --git a/test/toSafeInteger/toSafeInteger.test.js b/test/toSafeInteger/toSafeInteger.test.js index e04013774..508da718a 100644 --- a/test/toSafeInteger/toSafeInteger.test.js +++ b/test/toSafeInteger/toSafeInteger.test.js @@ -2,17 +2,17 @@ const test = require('tape'); const toSafeInteger = require('./toSafeInteger.js'); test('Testing toSafeInteger', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof toSafeInteger === 'function', 'toSafeInteger is a Function'); - t.equal(toSafeInteger(3.2), 3, "Converts a value to a safe integer"); - t.equal(toSafeInteger('4.2'), 4, "Converts a value to a safe integer"); - t.equal(toSafeInteger(4.6), 5, "Converts a value to a safe integer"); - t.equal(toSafeInteger(1.5), 2, "Converts a value to a safe integer"); - t.equal(toSafeInteger(Infinity), 9007199254740991, "Converts a value to a safe integer"); - //t.deepEqual(toSafeInteger(args..), 'Expected'); - //t.equal(toSafeInteger(args..), 'Expected'); - //t.false(toSafeInteger(args..), 'Expected'); - //t.throws(toSafeInteger(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof toSafeInteger === 'function', 'toSafeInteger is a Function'); + t.equal(toSafeInteger(3.2), 3, "Converts a value to a safe integer"); + t.equal(toSafeInteger('4.2'), 4, "Converts a value to a safe integer"); + t.equal(toSafeInteger(4.6), 5, "Converts a value to a safe integer"); + t.equal(toSafeInteger(1.5), 2, "Converts a value to a safe integer"); + t.equal(toSafeInteger(Infinity), 9007199254740991, "Converts a value to a safe integer"); + //t.deepEqual(toSafeInteger(args..), 'Expected'); + //t.equal(toSafeInteger(args..), 'Expected'); + //t.false(toSafeInteger(args..), 'Expected'); + //t.throws(toSafeInteger(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/toSnakeCase/toSnakeCase.js b/test/toSnakeCase/toSnakeCase.js index 9fffb9201..4e18c9123 100644 --- a/test/toSnakeCase/toSnakeCase.js +++ b/test/toSnakeCase/toSnakeCase.js @@ -4,4 +4,4 @@ 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 = toSnakeCase \ No newline at end of file +module.exports = toSnakeCase \ No newline at end of file diff --git a/test/toSnakeCase/toSnakeCase.test.js b/test/toSnakeCase/toSnakeCase.test.js index ae281a8a0..14bed623d 100644 --- a/test/toSnakeCase/toSnakeCase.test.js +++ b/test/toSnakeCase/toSnakeCase.test.js @@ -2,17 +2,17 @@ const test = require('tape'); const toSnakeCase = require('./toSnakeCase.js'); test('Testing toSnakeCase', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof toSnakeCase === 'function', 'toSnakeCase is a Function'); - t.equal(toSnakeCase('camelCase'), 'camel_case', "string converts to snake case"); - t.equal(toSnakeCase('some text'), 'some_text', "string converts to snake case"); - t.equal(toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens'), 'some_mixed_string_with_spaces_underscores_and_hyphens', "string converts to snake case"); - t.equal(toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'), 'i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html', "string converts to snake case"); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof toSnakeCase === 'function', 'toSnakeCase is a Function'); + t.equal(toSnakeCase('camelCase'), 'camel_case', "string converts to snake case"); + t.equal(toSnakeCase('some text'), 'some_text', "string converts to snake case"); + t.equal(toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens'), 'some_mixed_string_with_spaces_underscores_and_hyphens', "string converts to snake case"); + t.equal(toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'), 'i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html', "string converts to snake case"); - //t.deepEqual(toSnakeCase(args..), 'Expected'); - //t.equal(toSnakeCase(args..), 'Expected'); - //t.false(toSnakeCase(args..), 'Expected'); - //t.throws(toSnakeCase(args..), 'Expected'); - t.end(); + //t.deepEqual(toSnakeCase(args..), 'Expected'); + //t.equal(toSnakeCase(args..), 'Expected'); + //t.false(toSnakeCase(args..), 'Expected'); + //t.throws(toSnakeCase(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/toggleClass/toggleClass.js b/test/toggleClass/toggleClass.js index 2ad186b51..90de4b417 100644 --- a/test/toggleClass/toggleClass.js +++ b/test/toggleClass/toggleClass.js @@ -1,2 +1,2 @@ const toggleClass = (el, className) => el.classList.toggle(className); - module.exports = toggleClass \ No newline at end of file +module.exports = toggleClass \ No newline at end of file diff --git a/test/toggleClass/toggleClass.test.js b/test/toggleClass/toggleClass.test.js index a1c97c303..f7424a31d 100644 --- a/test/toggleClass/toggleClass.test.js +++ b/test/toggleClass/toggleClass.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const toggleClass = require('./toggleClass.js'); test('Testing toggleClass', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof toggleClass === 'function', 'toggleClass is a Function'); - //t.deepEqual(toggleClass(args..), 'Expected'); - //t.equal(toggleClass(args..), 'Expected'); - //t.false(toggleClass(args..), 'Expected'); - //t.throws(toggleClass(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof toggleClass === 'function', 'toggleClass is a Function'); + //t.deepEqual(toggleClass(args..), 'Expected'); + //t.equal(toggleClass(args..), 'Expected'); + //t.false(toggleClass(args..), 'Expected'); + //t.throws(toggleClass(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/tomorrow/tomorrow.js b/test/tomorrow/tomorrow.js index 5f70ab9af..cb644dc4e 100644 --- a/test/tomorrow/tomorrow.js +++ b/test/tomorrow/tomorrow.js @@ -1,2 +1,8 @@ -const tomorrow = () => new Date(new Date().getTime() + 86400000).toISOString().split('T')[0]; - module.exports = tomorrow \ No newline at end of file +const tomorrow = () => { +let t = new Date(); +t.setDate(t.getDate() + 1); +return `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, '0')}-${String( +t.getDate() +).padStart(2, '0')}`; +}; +module.exports = tomorrow \ No newline at end of file diff --git a/test/tomorrow/tomorrow.test.js b/test/tomorrow/tomorrow.test.js index 0e8ab6edf..f8490270f 100644 --- a/test/tomorrow/tomorrow.test.js +++ b/test/tomorrow/tomorrow.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const tomorrow = require('./tomorrow.js'); test('Testing tomorrow', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof tomorrow === 'function', 'tomorrow is a Function'); - //t.deepEqual(tomorrow(args..), 'Expected'); - //t.equal(tomorrow(args..), 'Expected'); - //t.false(tomorrow(args..), 'Expected'); - //t.throws(tomorrow(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof tomorrow === 'function', 'tomorrow is a Function'); + //t.deepEqual(tomorrow(args..), 'Expected'); + //t.equal(tomorrow(args..), 'Expected'); + //t.false(tomorrow(args..), 'Expected'); + //t.throws(tomorrow(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/transform/transform.js b/test/transform/transform.js index e6f4c6ef8..1232a4a9b 100644 --- a/test/transform/transform.js +++ b/test/transform/transform.js @@ -1,2 +1,2 @@ const transform = (obj, fn, acc) => Object.keys(obj).reduce((a, k) => fn(a, obj[k], k, obj), acc); - module.exports = transform \ No newline at end of file +module.exports = transform \ No newline at end of file diff --git a/test/transform/transform.test.js b/test/transform/transform.test.js index d32739d4a..957cddf20 100644 --- a/test/transform/transform.test.js +++ b/test/transform/transform.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const transform = require('./transform.js'); test('Testing transform', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof transform === 'function', 'transform is a Function'); - //t.deepEqual(transform(args..), 'Expected'); - //t.equal(transform(args..), 'Expected'); - //t.false(transform(args..), 'Expected'); - //t.throws(transform(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof transform === 'function', 'transform is a Function'); + //t.deepEqual(transform(args..), 'Expected'); + //t.equal(transform(args..), 'Expected'); + //t.false(transform(args..), 'Expected'); + //t.throws(transform(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/truncateString/truncateString.js b/test/truncateString/truncateString.js index 307d0c12b..ef9546701 100644 --- a/test/truncateString/truncateString.js +++ b/test/truncateString/truncateString.js @@ -1,3 +1,3 @@ const truncateString = (str, num) => str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str; - module.exports = truncateString \ No newline at end of file +module.exports = truncateString \ No newline at end of file diff --git a/test/truncateString/truncateString.test.js b/test/truncateString/truncateString.test.js index da3ce1d3c..8022f5a6c 100644 --- a/test/truncateString/truncateString.test.js +++ b/test/truncateString/truncateString.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const truncateString = require('./truncateString.js'); test('Testing truncateString', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof truncateString === 'function', 'truncateString is a Function'); - t.equal(truncateString('boomerang', 7), 'boom...', 'Truncates a "boomerang" up to a specified length.'); - //t.equal(truncateString(args..), 'Expected'); - //t.false(truncateString(args..), 'Expected'); - //t.throws(truncateString(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof truncateString === 'function', 'truncateString is a Function'); + t.equal(truncateString('boomerang', 7), 'boom...', 'Truncates a "boomerang" up to a specified length.'); + //t.equal(truncateString(args..), 'Expected'); + //t.false(truncateString(args..), 'Expected'); + //t.throws(truncateString(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/truthCheckCollection/truthCheckCollection.js b/test/truthCheckCollection/truthCheckCollection.js index 3841a8dce..8a7ada0b0 100644 --- a/test/truthCheckCollection/truthCheckCollection.js +++ b/test/truthCheckCollection/truthCheckCollection.js @@ -1,2 +1,2 @@ const truthCheckCollection = (collection, pre) => collection.every(obj => obj[pre]); - module.exports = truthCheckCollection \ No newline at end of file +module.exports = truthCheckCollection \ No newline at end of file diff --git a/test/truthCheckCollection/truthCheckCollection.test.js b/test/truthCheckCollection/truthCheckCollection.test.js index 80479572d..a844c925b 100644 --- a/test/truthCheckCollection/truthCheckCollection.test.js +++ b/test/truthCheckCollection/truthCheckCollection.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const truthCheckCollection = require('./truthCheckCollection.js'); test('Testing truthCheckCollection', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof truthCheckCollection === 'function', 'truthCheckCollection is a Function'); - t.equal(truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex: 'male' }], 'sex'), true, "second argument is truthy on all elements of a collection"); - //t.deepEqual(truthCheckCollection(args..), 'Expected'); - //t.equal(truthCheckCollection(args..), 'Expected'); - //t.false(truthCheckCollection(args..), 'Expected'); - //t.throws(truthCheckCollection(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof truthCheckCollection === 'function', 'truthCheckCollection is a Function'); + t.equal(truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex: 'male' }], 'sex'), true, "second argument is truthy on all elements of a collection"); + //t.deepEqual(truthCheckCollection(args..), 'Expected'); + //t.equal(truthCheckCollection(args..), 'Expected'); + //t.false(truthCheckCollection(args..), 'Expected'); + //t.throws(truthCheckCollection(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/unary/unary.js b/test/unary/unary.js new file mode 100644 index 000000000..524eb0113 --- /dev/null +++ b/test/unary/unary.js @@ -0,0 +1,2 @@ +const unary = fn => val => fn(val); +module.exports = unary \ No newline at end of file diff --git a/test/unary/unary.test.js b/test/unary/unary.test.js new file mode 100644 index 000000000..9a6f878f9 --- /dev/null +++ b/test/unary/unary.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const unary = require('./unary.js'); + +test('Testing unary', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof unary === 'function', 'unary is a Function'); + //t.deepEqual(unary(args..), 'Expected'); + //t.equal(unary(args..), 'Expected'); + //t.false(unary(args..), 'Expected'); + //t.throws(unary(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/unescapeHTML/unescapeHTML.js b/test/unescapeHTML/unescapeHTML.js index c4b6c379e..a82099aa1 100644 --- a/test/unescapeHTML/unescapeHTML.js +++ b/test/unescapeHTML/unescapeHTML.js @@ -10,4 +10,4 @@ tag => '"': '"' }[tag] || tag) ); - module.exports = unescapeHTML \ No newline at end of file +module.exports = unescapeHTML \ No newline at end of file diff --git a/test/unescapeHTML/unescapeHTML.test.js b/test/unescapeHTML/unescapeHTML.test.js index 5bd5d9eb9..460a20106 100644 --- a/test/unescapeHTML/unescapeHTML.test.js +++ b/test/unescapeHTML/unescapeHTML.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const unescapeHTML = require('./unescapeHTML.js'); test('Testing unescapeHTML', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof unescapeHTML === 'function', 'unescapeHTML is a Function'); - t.equal(unescapeHTML('<a href="#">Me & you</a>'), 'Me & you', 'Unescapes escaped HTML characters.'); - //t.deepEqual(unescapeHTML(args..), 'Expected'); - //t.equal(unescapeHTML(args..), 'Expected'); - //t.false(unescapeHTML(args..), 'Expected'); - //t.throws(unescapeHTML(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof unescapeHTML === 'function', 'unescapeHTML is a Function'); + t.equal(unescapeHTML('<a href="#">Me & you</a>'), 'Me & you', 'Unescapes escaped HTML characters.'); + //t.deepEqual(unescapeHTML(args..), 'Expected'); + //t.equal(unescapeHTML(args..), 'Expected'); + //t.false(unescapeHTML(args..), 'Expected'); + //t.throws(unescapeHTML(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/unfold/unfold.js b/test/unfold/unfold.js new file mode 100644 index 000000000..499ad0ab6 --- /dev/null +++ b/test/unfold/unfold.js @@ -0,0 +1,7 @@ +const unfold = (fn, seed) => { +let result = [], +val = [null, seed]; +while ((val = fn(val[1]))) result.push(val[0]); +return result; +}; +module.exports = unfold \ No newline at end of file diff --git a/test/unfold/unfold.test.js b/test/unfold/unfold.test.js new file mode 100644 index 000000000..ac4334008 --- /dev/null +++ b/test/unfold/unfold.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const unfold = require('./unfold.js'); + +test('Testing unfold', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof unfold === 'function', 'unfold is a Function'); + //t.deepEqual(unfold(args..), 'Expected'); + //t.equal(unfold(args..), 'Expected'); + //t.false(unfold(args..), 'Expected'); + //t.throws(unfold(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/union/union.js b/test/union/union.js index 1f86c4442..d0b4b52ea 100644 --- a/test/union/union.js +++ b/test/union/union.js @@ -1,2 +1,2 @@ const union = (a, b) => Array.from(new Set([...a, ...b])); - module.exports = union \ No newline at end of file +module.exports = union \ No newline at end of file diff --git a/test/union/union.test.js b/test/union/union.test.js index 1426f4a28..73427934a 100644 --- a/test/union/union.test.js +++ b/test/union/union.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const union = require('./union.js'); test('Testing union', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof union === 'function', 'union is a Function'); - t.deepEqual(union([1, 2, 3], [4, 3, 2]), [1, 2, 3, 4], "Returns every element that exists in any of the two arrays once"); - //t.deepEqual(union(args..), 'Expected'); - //t.equal(union(args..), 'Expected'); - //t.false(union(args..), 'Expected'); - //t.throws(union(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof union === 'function', 'union is a Function'); + t.deepEqual(union([1, 2, 3], [4, 3, 2]), [1, 2, 3, 4], "Returns every element that exists in any of the two arrays once"); + //t.deepEqual(union(args..), 'Expected'); + //t.equal(union(args..), 'Expected'); + //t.false(union(args..), 'Expected'); + //t.throws(union(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/unionBy/unionBy.js b/test/unionBy/unionBy.js new file mode 100644 index 000000000..d4afc4763 --- /dev/null +++ b/test/unionBy/unionBy.js @@ -0,0 +1,5 @@ +const unionBy = (a, b, fn) => { +const s = new Set(a.map(v => fn(v))); +return Array.from(new Set([...a, ...b.filter(x => !s.has(fn(x)))])); +}; +module.exports = unionBy \ No newline at end of file diff --git a/test/unionBy/unionBy.test.js b/test/unionBy/unionBy.test.js new file mode 100644 index 000000000..c59c4c303 --- /dev/null +++ b/test/unionBy/unionBy.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const unionBy = require('./unionBy.js'); + +test('Testing unionBy', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof unionBy === 'function', 'unionBy is a Function'); + //t.deepEqual(unionBy(args..), 'Expected'); + //t.equal(unionBy(args..), 'Expected'); + //t.false(unionBy(args..), 'Expected'); + //t.throws(unionBy(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/unionWith/unionWith.js b/test/unionWith/unionWith.js new file mode 100644 index 000000000..cb1ca174d --- /dev/null +++ b/test/unionWith/unionWith.js @@ -0,0 +1,3 @@ +const unionWith = (a, b, comp) => +Array.from(new Set([...a, ...b.filter(x => a.findIndex(y => comp(x, y)) === -1)])); +module.exports = unionWith \ No newline at end of file diff --git a/test/unionWith/unionWith.test.js b/test/unionWith/unionWith.test.js new file mode 100644 index 000000000..9b3f5ebfc --- /dev/null +++ b/test/unionWith/unionWith.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const unionWith = require('./unionWith.js'); + +test('Testing unionWith', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof unionWith === 'function', 'unionWith is a Function'); + //t.deepEqual(unionWith(args..), 'Expected'); + //t.equal(unionWith(args..), 'Expected'); + //t.false(unionWith(args..), 'Expected'); + //t.throws(unionWith(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/uniqueElements/uniqueElements.js b/test/uniqueElements/uniqueElements.js index 5e5b4315d..feb8e9b74 100644 --- a/test/uniqueElements/uniqueElements.js +++ b/test/uniqueElements/uniqueElements.js @@ -1,2 +1,2 @@ const uniqueElements = arr => [...new Set(arr)]; - module.exports = uniqueElements \ No newline at end of file +module.exports = uniqueElements \ No newline at end of file diff --git a/test/uniqueElements/uniqueElements.test.js b/test/uniqueElements/uniqueElements.test.js index d2e30f925..38d55aea5 100644 --- a/test/uniqueElements/uniqueElements.test.js +++ b/test/uniqueElements/uniqueElements.test.js @@ -2,13 +2,13 @@ const test = require('tape'); const uniqueElements = require('./uniqueElements.js'); test('Testing uniqueElements', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof uniqueElements === 'function', 'uniqueElements is a Function'); - t.deepEqual(uniqueElements([1, 2, 2, 3, 4, 4, 5]), [1,2,3,4,5], "Returns all unique values of an array"); - //t.deepEqual(uniqueElements(args..), 'Expected'); - //t.equal(uniqueElements(args..), 'Expected'); - //t.false(uniqueElements(args..), 'Expected'); - //t.throws(uniqueElements(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof uniqueElements === 'function', 'uniqueElements is a Function'); + t.deepEqual(uniqueElements([1, 2, 2, 3, 4, 4, 5]), [1,2,3,4,5], "Returns all unique values of an array"); + //t.deepEqual(uniqueElements(args..), 'Expected'); + //t.equal(uniqueElements(args..), 'Expected'); + //t.false(uniqueElements(args..), 'Expected'); + //t.throws(uniqueElements(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/untildify/untildify.js b/test/untildify/untildify.js index a95120fb9..4962b7567 100644 --- a/test/untildify/untildify.js +++ b/test/untildify/untildify.js @@ -1,2 +1,2 @@ const untildify = str => str.replace(/^~($|\/|\\)/, `${require('os').homedir()}$1`); - module.exports = untildify \ No newline at end of file +module.exports = untildify \ No newline at end of file diff --git a/test/untildify/untildify.test.js b/test/untildify/untildify.test.js index 0777b4917..3c3b286eb 100644 --- a/test/untildify/untildify.test.js +++ b/test/untildify/untildify.test.js @@ -2,12 +2,12 @@ const test = require('tape'); const untildify = require('./untildify.js'); test('Testing untildify', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof untildify === 'function', 'untildify is a Function'); - //t.deepEqual(untildify(args..), 'Expected'); - //t.equal(untildify(args..), 'Expected'); - //t.false(untildify(args..), 'Expected'); - //t.throws(untildify(args..), 'Expected'); - t.end(); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof untildify === 'function', 'untildify is a Function'); + //t.deepEqual(untildify(args..), 'Expected'); + //t.equal(untildify(args..), 'Expected'); + //t.false(untildify(args..), 'Expected'); + //t.throws(untildify(args..), 'Expected'); + t.end(); }); \ No newline at end of file diff --git a/test/unzip/unzip.js b/test/unzip/unzip.js new file mode 100644 index 000000000..4cfe50a93 --- /dev/null +++ b/test/unzip/unzip.js @@ -0,0 +1,8 @@ +const unzip = arr => +arr.reduce( +(acc, val) => (val.forEach((v, i) => acc[i].push(v)), acc), +Array.from({ +length: Math.max(...arr.map(x => x.length)) +}).map(x => []) +); +module.exports = unzip \ No newline at end of file diff --git a/test/unzip/unzip.test.js b/test/unzip/unzip.test.js new file mode 100644 index 000000000..acfddc110 --- /dev/null +++ b/test/unzip/unzip.test.js @@ -0,0 +1,15 @@ +const test = require('tape'); +const unzip = require('./unzip.js'); + +test('Testing unzip', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof unzip === 'function', 'unzip is a Function'); + t.deepEqual(unzip([['a', 1, true], ['b', 2, false]]), [['a', 'b'], [1, 2], [true, false]], `unzip([['a', 1, true], ['b', 2, false]]) equals [['a', 'b'], [1, 2], [true, false]]`); + t.deepEqual(unzip([['a', 1, true], ['b', 2]]), [['a', 'b'], [1, 2], [true]], `unzip([['a', 1, true], ['b', 2]]) equals [['a', 'b'], [1, 2], [true]]`); + //t.deepEqual(unzip(args..), 'Expected'); + //t.equal(unzip(args..), 'Expected'); + //t.false(unzip(args..), 'Expected'); + //t.throws(unzip(args..), 'Expected'); + t.end(); +}); diff --git a/test/unzipWith/unzipWith.js b/test/unzipWith/unzipWith.js new file mode 100644 index 000000000..6f1ba0869 --- /dev/null +++ b/test/unzipWith/unzipWith.js @@ -0,0 +1,10 @@ +const unzipWith = (arr, fn) => +arr +.reduce( +(acc, val) => (val.forEach((v, i) => acc[i].push(v)), acc), +Array.from({ +length: Math.max(...arr.map(x => x.length)) +}).map(x => []) +) +.map(val => fn(...val)); +module.exports = unzipWith \ No newline at end of file diff --git a/test/unzipWith/unzipWith.test.js b/test/unzipWith/unzipWith.test.js new file mode 100644 index 000000000..a9416e7c2 --- /dev/null +++ b/test/unzipWith/unzipWith.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const unzipWith = require('./unzipWith.js'); + +test('Testing unzipWith', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof unzipWith === 'function', 'unzipWith is a Function'); + t.deepEqual(unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0)), [3, 30, 300], `unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0)) equals [3, 30, 300]`); + //t.equal(unzipWith(args..), 'Expected'); + //t.false(unzipWith(args..), 'Expected'); + //t.throws(unzipWith(args..), 'Expected'); + t.end(); +}); diff --git a/test/validateNumber/validateNumber.js b/test/validateNumber/validateNumber.js index 05e4a8a06..1b03adf29 100644 --- a/test/validateNumber/validateNumber.js +++ b/test/validateNumber/validateNumber.js @@ -1,2 +1,2 @@ const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n; - module.exports = validateNumber \ No newline at end of file +module.exports = validateNumber \ No newline at end of file diff --git a/test/validateNumber/validateNumber.test.js b/test/validateNumber/validateNumber.test.js index 4f8908d88..e8037cc65 100644 --- a/test/validateNumber/validateNumber.test.js +++ b/test/validateNumber/validateNumber.test.js @@ -2,21 +2,21 @@ const test = require('tape'); const validateNumber = require('./validateNumber.js'); test('Testing validateNumber', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof validateNumber === 'function', 'validateNumber is a Function'); - t.true(validateNumber(9), 'validateNumber(9) returns true'); - t.true(validateNumber('234asd'.slice(0, 2)), 'validateNumber(234asd.slice(0, 2)) returns true'); - t.true(validateNumber(1232), 'validateNumber(1232) returns true'); - t.true(validateNumber(1232 + 13423), 'validateNumber(1232 + 13423) returns true'); - t.true(validateNumber(1232 * 2342 * 123), 'validateNumber(1232 * 2342 * 123) returns true'); - t.true(validateNumber(1232.23423536), 'validateNumber(1232.23423536) returns true'); - t.false(validateNumber('234asd'), 'validateNumber(234asd) returns false'); - t.false(validateNumber('e234d'), 'validateNumber(e234d) returns false'); - t.false(validateNumber(false), 'validateNumber(false) returns false'); - t.false(validateNumber(true), 'validateNumber(true) returns false'); - t.false(validateNumber(null), 'validateNumber(null) returns false'); - t.false(validateNumber(123 * 'asd'), 'validateNumber(123 * asd) returns false'); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof validateNumber === 'function', 'validateNumber is a Function'); + t.true(validateNumber(9), 'validateNumber(9) returns true'); + t.true(validateNumber('234asd'.slice(0, 2)), 'validateNumber(234asd.slice(0, 2)) returns true'); + t.true(validateNumber(1232), 'validateNumber(1232) returns true'); + t.true(validateNumber(1232 + 13423), 'validateNumber(1232 + 13423) returns true'); + t.true(validateNumber(1232 * 2342 * 123), 'validateNumber(1232 * 2342 * 123) returns true'); + t.true(validateNumber(1232.23423536), 'validateNumber(1232.23423536) returns true'); + t.false(validateNumber('234asd'), 'validateNumber(234asd) returns false'); + t.false(validateNumber('e234d'), 'validateNumber(e234d) returns false'); + t.false(validateNumber(false), 'validateNumber(false) returns false'); + t.false(validateNumber(true), 'validateNumber(true) returns false'); + t.false(validateNumber(null), 'validateNumber(null) returns false'); + t.false(validateNumber(123 * 'asd'), 'validateNumber(123 * asd) returns false'); - t.end(); + t.end(); }); diff --git a/test/without/without.js b/test/without/without.js index ffd99a9d3..598b31253 100644 --- a/test/without/without.js +++ b/test/without/without.js @@ -1,2 +1,2 @@ const without = (arr, ...args) => arr.filter(v => !args.includes(v)); - module.exports = without \ No newline at end of file +module.exports = without \ No newline at end of file diff --git a/test/without/without.test.js b/test/without/without.test.js index 09fdcb121..7d9fa7e70 100644 --- a/test/without/without.test.js +++ b/test/without/without.test.js @@ -2,18 +2,18 @@ const test = require('tape'); const without = require('./without.js'); test('Testing without', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof without === 'function', 'without is a Function'); - t.deepEqual(without([2, 1, 2, 3], 1, 2), [3], "without([2, 1, 2, 3], 1, 2) returns [3]"); - t.deepEqual(without([]), [], "without([]) returns []"); - t.deepEqual(without([3, 1, true, '3', true], '3', true), [3, 1], "without([3, 1, true, '3', true], '3', true) returns [3, 1]"); - t.deepEqual(without('string'.split(''), 's', 't', 'g'), ['r', 'i', 'n'], "without('string'.split(''), 's', 't', 'g') returns ['r', 'i', 'n']"); - t.throws(() => without(), 'without() throws an error'); - t.throws(() => without(null), 'without(null) throws an error'); - t.throws(() => without(undefined), 'without(undefined) throws an error'); - t.throws(() => without(123), 'without() throws an error'); - t.throws(() => without({}), 'without({}) throws an error'); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof without === 'function', 'without is a Function'); + t.deepEqual(without([2, 1, 2, 3], 1, 2), [3], "without([2, 1, 2, 3], 1, 2) returns [3]"); + t.deepEqual(without([]), [], "without([]) returns []"); + t.deepEqual(without([3, 1, true, '3', true], '3', true), [3, 1], "without([3, 1, true, '3', true], '3', true) returns [3, 1]"); + t.deepEqual(without('string'.split(''), 's', 't', 'g'), ['r', 'i', 'n'], "without('string'.split(''), 's', 't', 'g') returns ['r', 'i', 'n']"); + t.throws(() => without(), 'without() throws an error'); + t.throws(() => without(null), 'without(null) throws an error'); + t.throws(() => without(undefined), 'without(undefined) throws an error'); + t.throws(() => without(123), 'without() throws an error'); + t.throws(() => without({}), 'without({}) throws an error'); - t.end(); + t.end(); }); diff --git a/test/words/words.js b/test/words/words.js index 936b7d6ca..d26c714fa 100644 --- a/test/words/words.js +++ b/test/words/words.js @@ -1,2 +1,2 @@ const words = (str, pattern = /[^a-zA-Z-]+/) => str.split(pattern).filter(Boolean); - module.exports = words \ No newline at end of file +module.exports = words \ No newline at end of file diff --git a/test/words/words.test.js b/test/words/words.test.js index bb92b2c10..1c8a7fda7 100644 --- a/test/words/words.test.js +++ b/test/words/words.test.js @@ -2,18 +2,18 @@ const test = require('tape'); const words = require('./words.js'); test('Testing words', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof words === 'function', 'words is a Function'); - t.deepEqual(words('I love javaScript!!'), ["I", "love", "javaScript"], "words('I love javaScript!!') returns [I, love, javaScript]"); - t.deepEqual(words('python, javaScript & coffee'), ["python", "javaScript", "coffee"], "words('python, javaScript & coffee') returns [python, javaScript, coffee]"); - t.true(Array.isArray(words('I love javaScript!!')), 'words(I love javaScript!!) returns an array'); - t.throws(() => words(), 'words() throws a error'); - t.throws(() => words(null), 'words(null) throws a error'); - t.throws(() => words(undefined), 'words(undefined) throws a error'); - t.throws(() => words({}), 'words({}) throws a error'); - t.throws(() => words([]), 'words([]) throws a error'); - t.throws(() => words(1234), 'words(1234) throws a error'); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof words === 'function', 'words is a Function'); + t.deepEqual(words('I love javaScript!!'), ["I", "love", "javaScript"], "words('I love javaScript!!') returns [I, love, javaScript]"); + t.deepEqual(words('python, javaScript & coffee'), ["python", "javaScript", "coffee"], "words('python, javaScript & coffee') returns [python, javaScript, coffee]"); + t.true(Array.isArray(words('I love javaScript!!')), 'words(I love javaScript!!) returns an array'); + t.throws(() => words(), 'words() throws a error'); + t.throws(() => words(null), 'words(null) throws a error'); + t.throws(() => words(undefined), 'words(undefined) throws a error'); + t.throws(() => words({}), 'words({}) throws a error'); + t.throws(() => words([]), 'words([]) throws a error'); + t.throws(() => words(1234), 'words(1234) throws a error'); - t.end(); + t.end(); }); diff --git a/test/xProd/xProd.js b/test/xProd/xProd.js new file mode 100644 index 000000000..2b7a126c3 --- /dev/null +++ b/test/xProd/xProd.js @@ -0,0 +1,2 @@ +const xProd = (a, b) => a.reduce((acc, x) => acc.concat(b.map(y => [x, y])), []); +module.exports = xProd \ No newline at end of file diff --git a/test/xProd/xProd.test.js b/test/xProd/xProd.test.js new file mode 100644 index 000000000..9bc6571de --- /dev/null +++ b/test/xProd/xProd.test.js @@ -0,0 +1,14 @@ +const test = require('tape'); +const xProd = require('./xProd.js'); + +test('Testing xProd', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof xProd === 'function', 'xProd is a Function'); + t.deepEqual(xProd([1, 2], ['a', 'b']), [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']], `xProd([1, 2], ['a', 'b']) returns [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]`); + //t.deepEqual(xProd(args..), 'Expected'); + //t.equal(xProd(args..), 'Expected'); + //t.false(xProd(args..), 'Expected'); + //t.throws(xProd(args..), 'Expected'); + t.end(); +}); diff --git a/test/yesNo/yesNo.js b/test/yesNo/yesNo.js index 437338d17..11a2a248a 100644 --- a/test/yesNo/yesNo.js +++ b/test/yesNo/yesNo.js @@ -1,3 +1,3 @@ const yesNo = (val, def = false) => /^(y|yes)$/i.test(val) ? true : /^(n|no)$/i.test(val) ? false : def; - module.exports = yesNo \ No newline at end of file +module.exports = yesNo \ No newline at end of file diff --git a/test/yesNo/yesNo.test.js b/test/yesNo/yesNo.test.js index c50e452db..6b7c66d1c 100644 --- a/test/yesNo/yesNo.test.js +++ b/test/yesNo/yesNo.test.js @@ -2,21 +2,21 @@ const test = require('tape'); const yesNo = require('./yesNo.js'); test('Testing yesNo', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof yesNo === 'function', 'yesNo is a Function'); - t.true(yesNo('Y'), 'yesNo(Y) returns true'); - t.true(yesNo('yes'), 'yesNo(yes) returns true'); - t.true(yesNo('foo', true), 'yesNo(foo, true) returns true'); - t.false(yesNo('No'), 'yesNo(No) returns false'); - t.false(yesNo(), 'yesNo() returns false'); - t.false(yesNo(null), 'yesNo(null) returns false'); - t.false(yesNo(undefined), 'yesNo(undefined) returns false'); - t.false(yesNo([123, null]), 'yesNo([123, null]) returns false'); - t.false(yesNo(['Yes', 'No']), 'yesNo([Yes, No]) returns false'); - t.false(yesNo({ 2: 'Yes' }), 'yesNo({ 2: Yes }) returns false'); - t.true(yesNo(['Yes', 'No'], true), 'yesNo([Yes, No], true) returns true'); - t.true(yesNo({ 2: 'Yes' }, true), 'yesNo({ 2: Yes }, true) returns true'); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof yesNo === 'function', 'yesNo is a Function'); + t.true(yesNo('Y'), 'yesNo(Y) returns true'); + t.true(yesNo('yes'), 'yesNo(yes) returns true'); + t.true(yesNo('foo', true), 'yesNo(foo, true) returns true'); + t.false(yesNo('No'), 'yesNo(No) returns false'); + t.false(yesNo(), 'yesNo() returns false'); + t.false(yesNo(null), 'yesNo(null) returns false'); + t.false(yesNo(undefined), 'yesNo(undefined) returns false'); + t.false(yesNo([123, null]), 'yesNo([123, null]) returns false'); + t.false(yesNo(['Yes', 'No']), 'yesNo([Yes, No]) returns false'); + t.false(yesNo({ 2: 'Yes' }), 'yesNo({ 2: Yes }) returns false'); + t.true(yesNo(['Yes', 'No'], true), 'yesNo([Yes, No], true) returns true'); + t.true(yesNo({ 2: 'Yes' }, true), 'yesNo({ 2: Yes }, true) returns true'); - t.end(); + t.end(); }); diff --git a/test/zip/zip.js b/test/zip/zip.js index e248b5de5..60ad9d244 100644 --- a/test/zip/zip.js +++ b/test/zip/zip.js @@ -4,4 +4,4 @@ return Array.from({ length: maxLength }).map((_, i) => { return Array.from({ length: arrays.length }, (_, k) => arrays[k][i]); }); }; - module.exports = zip \ No newline at end of file +module.exports = zip \ No newline at end of file diff --git a/test/zip/zip.test.js b/test/zip/zip.test.js index c198670d9..8e6ce6747 100644 --- a/test/zip/zip.test.js +++ b/test/zip/zip.test.js @@ -2,17 +2,17 @@ const test = require('tape'); const zip = require('./zip.js'); test('Testing zip', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof zip === 'function', 'zip is a Function'); - t.deepEqual(zip(['a', 'b'], [1, 2], [true, false]), [['a', 1, true], ['b', 2, false]], 'zip([a, b], [1, 2], [true, false]) returns [[a, 1, true], [b, 2, false]]'); - t.deepEqual(zip(['a'], [1, 2], [true, false]), [['a', 1, true], [undefined, 2, false]], 'zip([a], [1, 2], [true, false]) returns [[a, 1, true], [undefined, 2, false]]'); - t.deepEqual(zip(), [], 'zip([]) returns []'); - t.deepEqual(zip(123), [], 'zip(123) returns []'); - t.true(Array.isArray(zip(['a', 'b'], [1, 2], [true, false])), 'zip([a, b], [1, 2], [true, false]) returns an Array'); - t.true(Array.isArray(zip(['a'], [1, 2], [true, false])), 'zip([a], [1, 2], [true, false]) returns an Array'); - t.throws(() => zip(null), 'zip(null) throws an error'); - t.throws(() => zip(undefined), 'zip(undefined) throws an error'); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof zip === 'function', 'zip is a Function'); + t.deepEqual(zip(['a', 'b'], [1, 2], [true, false]), [['a', 1, true], ['b', 2, false]], 'zip([a, b], [1, 2], [true, false]) returns [[a, 1, true], [b, 2, false]]'); + t.deepEqual(zip(['a'], [1, 2], [true, false]), [['a', 1, true], [undefined, 2, false]], 'zip([a], [1, 2], [true, false]) returns [[a, 1, true], [undefined, 2, false]]'); + t.deepEqual(zip(), [], 'zip([]) returns []'); + t.deepEqual(zip(123), [], 'zip(123) returns []'); + t.true(Array.isArray(zip(['a', 'b'], [1, 2], [true, false])), 'zip([a, b], [1, 2], [true, false]) returns an Array'); + t.true(Array.isArray(zip(['a'], [1, 2], [true, false])), 'zip([a], [1, 2], [true, false]) returns an Array'); + t.throws(() => zip(null), 'zip(null) throws an error'); + t.throws(() => zip(undefined), 'zip(undefined) throws an error'); - t.end(); + t.end(); }); diff --git a/test/zipObject/zipObject.js b/test/zipObject/zipObject.js index 7e1f6f633..e077594b4 100644 --- a/test/zipObject/zipObject.js +++ b/test/zipObject/zipObject.js @@ -1,3 +1,3 @@ const zipObject = (props, values) => props.reduce((obj, prop, index) => ((obj[prop] = values[index]), obj), {}); - module.exports = zipObject \ No newline at end of file +module.exports = zipObject \ No newline at end of file diff --git a/test/zipObject/zipObject.test.js b/test/zipObject/zipObject.test.js index ab0f9223d..83ba782a0 100644 --- a/test/zipObject/zipObject.test.js +++ b/test/zipObject/zipObject.test.js @@ -2,18 +2,18 @@ const test = require('tape'); const zipObject = require('./zipObject.js'); test('Testing zipObject', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof zipObject === 'function', 'zipObject is a Function'); - t.deepEqual(zipObject(['a', 'b', 'c'], [1, 2]), {a: 1, b: 2, c: undefined}, 'zipObject([a, b, c], [1, 2]) returns {a: 1, b: 2, c: undefined}'); - t.deepEqual(zipObject(['a', 'b'], [1, 2, 3]), {a: 1, b: 2}, 'zipObject([a, b], [1, 2, 3]) returns {a: 1, b: 2}'); - t.deepEqual(zipObject(['a', 'b', 'c'], 'string'), { a: 's', b: 't', c: 'r' }, 'zipObject([a, b, c], string) returns { a: s, b: t, c: r }'); - t.deepEqual(zipObject(['a'], 'string'), { a: 's' }, 'zipObject([a], string) returns { a: s }'); - t.throws(() => zipObject(), 'zipObject() throws an error'); - t.throws(() => zipObject(['string'], null), 'zipObject([string], null) throws an error'); - t.throws(() => zipObject(null, [1]), 'zipObject(null, [1]) throws an error'); - t.throws(() => zipObject('string'), 'zipObject(string) throws an error'); - t.throws(() => zipObject('test', 'string'), 'zipObject(test, string) throws an error'); + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof zipObject === 'function', 'zipObject is a Function'); + t.deepEqual(zipObject(['a', 'b', 'c'], [1, 2]), {a: 1, b: 2, c: undefined}, 'zipObject([a, b, c], [1, 2]) returns {a: 1, b: 2, c: undefined}'); + t.deepEqual(zipObject(['a', 'b'], [1, 2, 3]), {a: 1, b: 2}, 'zipObject([a, b], [1, 2, 3]) returns {a: 1, b: 2}'); + t.deepEqual(zipObject(['a', 'b', 'c'], 'string'), { a: 's', b: 't', c: 'r' }, 'zipObject([a, b, c], string) returns { a: s, b: t, c: r }'); + t.deepEqual(zipObject(['a'], 'string'), { a: 's' }, 'zipObject([a], string) returns { a: s }'); + t.throws(() => zipObject(), 'zipObject() throws an error'); + t.throws(() => zipObject(['string'], null), 'zipObject([string], null) throws an error'); + t.throws(() => zipObject(null, [1]), 'zipObject(null, [1]) throws an error'); + t.throws(() => zipObject('string'), 'zipObject(string) throws an error'); + t.throws(() => zipObject('test', 'string'), 'zipObject(test, string) throws an error'); - t.end(); + t.end(); }); diff --git a/test/zipWith/zipWith.js b/test/zipWith/zipWith.js new file mode 100644 index 000000000..39d5d18bb --- /dev/null +++ b/test/zipWith/zipWith.js @@ -0,0 +1,11 @@ +const zipWith = (...arrays) => { +const length = arrays.length; +let fn = length > 1 ? arrays[length - 1] : undefined; +fn = typeof fn == 'function' ? (arrays.pop(), fn) : undefined; +const maxLength = Math.max(...arrays.map(x => x.length)); +const result = Array.from({ length: maxLength }).map((_, i) => { +return Array.from({ length: arrays.length }, (_, k) => arrays[k][i]); +}); +return fn ? result.map(arr => fn(...arr)) : result; +}; +module.exports = zipWith \ No newline at end of file diff --git a/test/zipWith/zipWith.test.js b/test/zipWith/zipWith.test.js new file mode 100644 index 000000000..2cf409e24 --- /dev/null +++ b/test/zipWith/zipWith.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const zipWith = require('./zipWith.js'); + +test('Testing zipWith', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof zipWith === 'function', 'zipWith is a Function'); + //t.deepEqual(zipWith(args..), 'Expected'); + //t.equal(zipWith(args..), 'Expected'); + //t.false(zipWith(args..), 'Expected'); + //t.throws(zipWith(args..), 'Expected'); + t.end(); +}); \ No newline at end of file