diff --git a/README.md b/README.md index dbac6a8ce..c9d595d3d 100644 --- a/README.md +++ b/README.md @@ -1871,7 +1871,7 @@ longestItem([1, 2, 3], 'foobar'); // 'foobar' ### mapObject ![advanced](/advanced.svg) -Maps the values of an array to an object using a function, where the key-value pairs consist of the original value as the key and the mapped value. +Maps the values of an array to an object using a function, where the key-value pairs consist of the stringified value as the key and the mapped value. Use an anonymous inner function scope to declare an undefined memory space, using closures to store a return value. Use a new `Array` to store the array with a map of the function over its data set and a comma operator to return a second step, without needing to move from one context to another (due to closures and order of operations). @@ -4731,6 +4731,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]); + const lengthIs4 = checkProp(l => l === 4, 'length'); lengthIs4([]); // false lengthIs4([1,2,3,4]); // true diff --git a/docs/function.html b/docs/function.html index 592e8f539..71d58398e 100644 --- a/docs/function.html +++ b/docs/function.html @@ -149,6 +149,7 @@ console.log< + const lengthIs4 = checkProp(l => l === 4, 'length'); lengthIs4([]); // false lengthIs4([1,2,3,4]); // true diff --git a/docs/index.html b/docs/index.html index a0f91003e..8028b8275 100644 --- a/docs/index.html +++ b/docs/index.html @@ -294,7 +294,7 @@ longestItem(...['a', 'ab', 'abc'], 'abcd'); // 'abcd' longestItem([1, 2, 3], [1, 2], [1, 2, 3, 4, 5]); // [1, 2, 3, 4, 5] longestItem([1, 2, 3], 'foobar'); // 'foobar' -

mapObject

Maps the values of an array to an object using a function, where the key-value pairs consist of the original value as the key and the mapped value.

Use an anonymous inner function scope to declare an undefined memory space, using closures to store a return value. Use a new Array to store the array with a map of the function over its data set and a comma operator to return a second step, without needing to move from one context to another (due to closures and order of operations).

const mapObject = (arr, fn) =>
+

mapObject

Maps the values of an array to an object using a function, where the key-value pairs consist of the stringified value as the key and the mapped value.

Use an anonymous inner function scope to declare an undefined memory space, using closures to store a return value. Use a new Array to store the array with a map of the function over its data set and a comma operator to return a second step, without needing to move from one context to another (due to closures and order of operations).

const mapObject = (arr, fn) =>
   (a => (
     (a = [arr, arr.map(fn)]), a[0].reduce((acc, val, ind) => ((acc[val] = a[1][ind]), acc), {})
   ))();
diff --git a/snippets/checkProp.md b/snippets/checkProp.md
index 41e26c9e8..4644eb666 100644
--- a/snippets/checkProp.md
+++ b/snippets/checkProp.md
@@ -14,6 +14,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
 
 
 
+
 const lengthIs4 = checkProp(l => l === 4, 'length');
 lengthIs4([]); // false
 lengthIs4([1,2,3,4]); // true