diff --git a/README.md b/README.md index 7b51d37af..4178c83de 100644 --- a/README.md +++ b/README.md @@ -1828,8 +1828,7 @@ Returns `undefined` if no arguments are provided. Use `Array.prototype.reduce()`, comparing the `length` of objects to find the longest one. ```js -const longestItem = (val, ...vals) => - [val, ...vals].reduce((a, x) => (x.length > a.length ? x : a)); +const longestItem = (...vals) => vals.reduce((a, x) => (x.length > a.length ? x : a)); ```
diff --git a/docs/index.html b/docs/index.html index 8a1944e4c..b55e67cd0 100644 --- a/docs/index.html +++ b/docs/index.html @@ -280,8 +280,7 @@ JSONtoCSV([{ a: 1, b: 2 }, { a: 3, b: 4, c: 5 }, { a: 6 }, { b: 7 }], ['a', 'b'], ';'); // 'a;b\n"1";"2"\n"3";"4"\n"6";""\n"";"7"'

last

Returns the last element in an array.

Use arr.length - 1 to compute the index of the last element of the given array and returning it.

const last = arr => arr[arr.length - 1];
 
last([1, 2, 3]); // 3
-

longestItem

Takes any number of iterable objects or objects with a length property and returns the longest one. If multiple objects have the same length, the first one will be returned. Returns undefined if no arguments are provided.

Use Array.prototype.reduce(), comparing the length of objects to find the longest one.

const longestItem = (val, ...vals) =>
-  [val, ...vals].reduce((a, x) => (x.length > a.length ? x : a));
+

longestItem

Takes any number of iterable objects or objects with a length property and returns the longest one. If multiple objects have the same length, the first one will be returned. Returns undefined if no arguments are provided.

Use Array.prototype.reduce(), comparing the length of objects to find the longest one.

const longestItem = (...vals) => vals.reduce((a, x) => (x.length > a.length ? x : a));
 
longestItem('this', 'is', 'a', 'testcase'); // 'testcase'
 longestItem(...['a', 'ab', 'abc']); // 'abc'
 longestItem(...['a', 'ab', 'abc'], 'abcd'); // 'abcd'
diff --git a/snippets/longestItem.md b/snippets/longestItem.md
index dd8203682..c1c72e2d6 100644
--- a/snippets/longestItem.md
+++ b/snippets/longestItem.md
@@ -7,8 +7,7 @@ Returns `undefined` if no arguments are provided.
 Use `Array.prototype.reduce()`, comparing the `length` of objects to find the longest one.
 
 ```js
-const longestItem = (...vals) =>
-  vals.reduce((a, x) => (x.length > a.length ? x : a));
+const longestItem = (...vals) => vals.reduce((a, x) => (x.length > a.length ? x : a));
 ```
 
 ```js
diff --git a/test/_30s.js b/test/_30s.js
index d01db9149..21bddc484 100644
--- a/test/_30s.js
+++ b/test/_30s.js
@@ -642,8 +642,7 @@ const lcm = (...arr) => {
   const _lcm = (x, y) => (x * y) / gcd(x, y);
   return [...arr].reduce((a, b) => _lcm(a, b));
 };
-const longestItem = (val, ...vals) =>
-  [val, ...vals].reduce((a, x) => (x.length > a.length ? x : a));
+const longestItem = (...vals) => vals.reduce((a, x) => (x.length > a.length ? x : a));
 const lowercaseKeys = obj =>
   Object.keys(obj).reduce((acc, key) => {
     acc[key.toLowerCase()] = obj[key];