From 435260d6f455dbc3d81e35dc9a493cd45d8ccb3d Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Fri, 19 Jan 2018 11:07:33 +0000 Subject: [PATCH] Travis build: 1312 --- README.md | 34 ---------------------------------- docs/index.html | 16 ++-------------- 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 6219cc983..776caf373 100644 --- a/README.md +++ b/README.md @@ -272,7 +272,6 @@ average(1, 2, 3);
View contents -* [`cleanObj`](#cleanobj) * [`equals`](#equals-) * [`forOwn`](#forown) * [`forOwnRight`](#forownright) @@ -4156,39 +4155,6 @@ UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc' --- ## 🗃️ Object -### 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) - - ### equals ![advanced](/advanced.svg) Performs a deep comparison between two values to determine if they are equivalent. diff --git a/docs/index.html b/docs/index.html index ece1300fc..5be83bae2 100644 --- a/docs/index.html +++ b/docs/index.html @@ -50,7 +50,7 @@ scrollToTop(); } }, false); - }

logo 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

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);
+      }

logo 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

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);
 
Promise.resolve([1, 2, 3])
   .then(call('map', x => 2 * x))
   .then(console.log); //[ 2, 4, 6 ]
@@ -916,19 +916,7 @@ console.log<
     (c ^ (crypto.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
   );
 
UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc'
-

Object

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.

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;
-};
-
const testObj = { a: 1, b: 2, children: { a: 1, b: 2 } };
-cleanObj(testObj, ['a'], 'children'); // { a: 1, children : { a: 1}}
-

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 Date objects with the same time, using Date.getTime() or if they are both non-object values with an equivalent value (strict comparison). Check if only one value is null or undefined or if their prototypes differ. If none of the above conditions are met, use Object.keys() to check if both values have the same number of keys, then use Array.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) => {
+

Object

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 Date objects with the same time, using Date.getTime() or if they are both non-object values with an equivalent value (strict comparison). Check if only one value is null or undefined or if their prototypes differ. If none of the above conditions are met, use Object.keys() to check if both values have the same number of keys, then use Array.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;
   if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
   if (!a || !b || (typeof a != 'object' && typeof b !== 'object')) return a === b;