From b789929fd1e3784684952925fa90f5a6e8cd784a Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Mon, 26 Feb 2018 12:11:09 +0000 Subject: [PATCH] Travis build: 1746 --- README.md | 7 ++++--- docs/index.html | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 80ff561a8..b1295b78d 100644 --- a/README.md +++ b/README.md @@ -2339,16 +2339,17 @@ sortedLastIndex([10, 20, 30, 30, 40], 30); // 3 Returns the highest index at which value should be inserted into array in order to maintain its sort order, based on a provided iterator function. Check if the array is sorted in descending order (loosely). -Use `Array.reverse()` and `Array.findIndex()` to find the appropriate last index where the element should be inserted, based on the iterator function `fn`.. +Use `Array.map()` to apply the iterator function to all elements of the array. +Use `Array.reverse()` and `Array.findIndex()` to find the appropriate last index where the element should be inserted, based on the provided iterator function. ```js const sortedLastIndexBy = (arr, n, fn) => { const isDescending = fn(arr[0]) > fn(arr[arr.length - 1]); const val = fn(n); const index = arr - .map((val, i) => [i, fn(val)]) + .map(fn) .reverse() - .findIndex(el => (isDescending ? val <= el[1] : val >= el[1])); + .findIndex(el => (isDescending ? val <= el : val >= el)); return index === -1 ? 0 : arr.length - index; }; ``` diff --git a/docs/index.html b/docs/index.html index 6da1d2431..6cc929870 100644 --- a/docs/index.html +++ b/docs/index.html @@ -470,13 +470,13 @@ Object.assig return index === -1 ? 0 : arr.length - index - 1; };
sortedLastIndex([10, 20, 30, 30, 40], 30); // 3
-

sortedLastIndexBy

Returns the highest index at which value should be inserted into array in order to maintain its sort order, based on a provided iterator function.

Check if the array is sorted in descending order (loosely). Use Array.reverse() and Array.findIndex() to find the appropriate last index where the element should be inserted, based on the iterator function fn..

const sortedLastIndexBy = (arr, n, fn) => {
+

sortedLastIndexBy

Returns the highest index at which value should be inserted into array in order to maintain its sort order, based on a provided iterator function.

Check if the array is sorted in descending order (loosely). Use Array.map() to apply the iterator function to all elements of the array. Use Array.reverse() and Array.findIndex() to find the appropriate last index where the element should be inserted, based on the provided iterator function.

const sortedLastIndexBy = (arr, n, fn) => {
   const isDescending = fn(arr[0]) > fn(arr[arr.length - 1]);
   const val = fn(n);
   const index = arr
-    .map((val, i) => [i, fn(val)])
+    .map(fn)
     .reverse()
-    .findIndex(el => (isDescending ? val <= el[1] : val >= el[1]));
+    .findIndex(el => (isDescending ? val <= el : val >= el));
   return index === -1 ? 0 : arr.length - index;
 };
 
sortedLastIndexBy([{ x: 4 }, { x: 5 }], { x: 4 }, o => o.x); // 1