From f7484d30cc1cd32789074baf332a89012dcf5296 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Mon, 8 Jan 2018 20:01:19 +0000 Subject: [PATCH] Travis build: 1081 --- README.md | 32 ++++++++++++++++++++++++++++++++ docs/index.html | 10 ++++++++-- snippets/longestItem.md | 6 +++--- tag_database | 1 + 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 55a0fcc7c..fce180c51 100644 --- a/README.md +++ b/README.md @@ -339,6 +339,15 @@ average(1, 2, 3); +### _Uncategorized_ + +
+View contents + +* [`longestItem`](#longestitem) + +
+ --- ## 🔌 Adapter @@ -5257,6 +5266,29 @@ yesNo('Foo', true); // true
[⬆ Back to top](#table-of-contents) +--- + ## _Uncategorized_ + +### longestItem + +Takes any number of iterable objects or objects with a `length` property and returns the longest one. + +Use `Array.sort()` to sort all arguments by `length`, return the first (longest) one. + +```js +const longestItem = (...vals) => [...vals].sort((a, b) => b.length - a.length)[0]; +``` + +```js +longestItem('this', 'is', 'a', 'testcase'); // 'testcase' +longestItem(...['a', 'ab', 'abc']); // 'abc' +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' +``` + +
[⬆ back to top](#table-of-contents) + ## Collaborators diff --git a/docs/index.html b/docs/index.html index 8aba44eae..5a1aa76e4 100644 --- a/docs/index.html +++ b/docs/index.html @@ -40,7 +40,7 @@ },1700); } }, 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 ]
@@ -1132,4 +1132,10 @@ console.log<
 yesNo('yes'); // true
 yesNo('No'); // false
 yesNo('Foo', true); // true
-
\ No newline at end of file +

Uncategorized

longestItem

Takes any number of iterable objects or objects with a length property and returns the longest one.

Use Array.sort() to sort all arguments by length, return the first (longest) one.

const longestItem = (...vals) => [...vals].sort((a, b) => b.length - a.length)[0];
+
longestItem('this', 'is', 'a', 'testcase'); // 'testcase'
+longestItem(...['a', 'ab', 'abc']); // 'abc'
+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'
+
\ No newline at end of file diff --git a/snippets/longestItem.md b/snippets/longestItem.md index db4371ca8..ca61d93f4 100644 --- a/snippets/longestItem.md +++ b/snippets/longestItem.md @@ -9,9 +9,9 @@ const longestItem = (...vals) => [...vals].sort((a, b) => b.length - a.length)[0 ``` ```js -longestItem ('this', 'is', 'a', 'testcase'); // 'testcase' -longestItem (...['a', 'ab', 'abc']); // 'abc' -longestItem (...['a', 'ab', 'abc'], 'abcd'); // 'abcd' +longestItem('this', 'is', 'a', 'testcase'); // 'testcase' +longestItem(...['a', 'ab', 'abc']); // 'abc' +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' ``` diff --git a/tag_database b/tag_database index 51f680a67..4daa46e42 100644 --- a/tag_database +++ b/tag_database @@ -93,6 +93,7 @@ join:array JSONToFile:node,json last:array lcm:math,recursion +longestItem:uncategorized lowercaseKeys:object luhnCheck:math,utility mapObject:array,object