From cd998952353a3b8b86152447866735322b7191e7 Mon Sep 17 00:00:00 2001 From: Kaspar Vollenweider Date: Fri, 4 Feb 2022 13:22:20 +0100 Subject: [PATCH 1/3] fix(header_order): _.uniqWith h3 in wrong section It wasn in the wrong place, not after _.uniq, as expected. Additionally it's "Browser Support" header was h3 instead h4, so that didn't help with semantics and navigation as well. --- README.md | 66 +++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 86eef2d..7b55ba4 100644 --- a/README.md +++ b/README.md @@ -1799,6 +1799,39 @@ Produces a duplicate-free version of the array, using === to test object equalit **[⬆ back to top](#quick-links)** +### _.uniqWith + +similar to _.uniq except that it accepts comparator which is invoked to compare elements of array. The order of result values is determined by the order they occur in the array. + + ```js + // Lodash + const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }]; + const result = _.uniqWith(objects, _.isEqual); + console.log(result); + // output: [{ x: 1, y: 2 }, { x: 2, y: 1 }] + + // Native + const uniqWith = (arr, fn) => arr.filter((element, index) => arr.findIndex((step) => fn(element, step)) === index); + + const array = [1, 2, 2, 3, 4, 5, 2]; + const result = uniqWith(array, (a, b) => a === b); + console.log(result); + // output: [1, 2, 3, 4, 5] + + const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }]; + const result = uniqWith(objects, (a, b) => JSON.stringify(a) === JSON.stringify(b)); + console.log(result); + // output: [{ x: 1, y: 2 }, { x: 2, y: 1 }] + ``` + +#### Browser Support for `Array.prototype.filter()` and `Array.prototype.findIndex()` + +![Chrome][chrome-image] | ![Edge][edge-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] +:-: | :-: | :-: | :-: | :-: | :-: | + 45.0 ✔ | 12.0 ✔ | 25.0 ✔ | ✖ | 32.0 ✔ | 8.0 ✔ | + +**[⬆ back to top](#quick-links)** + ## Function ### _.after @@ -3091,39 +3124,6 @@ Uppercases the first letter of a given string **[⬆ back to top](#quick-links)** -### _.uniqWith - -similar to _.uniq except that it accepts comparator which is invoked to compare elements of array. The order of result values is determined by the order they occur in the array. - - ```js - // Lodash - const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }]; - const result = _.uniqWith(objects, _.isEqual); - console.log(result); - // output: [{ x: 1, y: 2 }, { x: 2, y: 1 }] - - // Native - const uniqWith = (arr, fn) => arr.filter((element, index) => arr.findIndex((step) => fn(element, step)) === index); - - const array = [1, 2, 2, 3, 4, 5, 2]; - const result = uniqWith(array, (a, b) => a === b); - console.log(result); - // output: [1, 2, 3, 4, 5] - - const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }]; - const result = uniqWith(objects, (a, b) => JSON.stringify(a) === JSON.stringify(b)); - console.log(result); - // output: [{ x: 1, y: 2 }, { x: 2, y: 1 }] - ``` - -### Browser Support for `Array.prototype.filter()` and `Array.prototype.findIndex()` - -![Chrome][chrome-image] | ![Edge][edge-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] -:-: | :-: | :-: | :-: | :-: | :-: | - 45.0 ✔ | 12.0 ✔ | 25.0 ✔ | ✖ | 32.0 ✔ | 8.0 ✔ | - -**[⬆ back to top](#quick-links)** - ## Util ### _.times From 6d217eaa9e0154d596af722c105587ea617e4358 Mon Sep 17 00:00:00 2001 From: Kaspar Vollenweider Date: Fri, 4 Feb 2022 13:29:31 +0100 Subject: [PATCH 2/3] fix(header_order): _.random header indentation --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7b55ba4..72b0b2e 100644 --- a/README.md +++ b/README.md @@ -3243,7 +3243,8 @@ Checks if n is between start and up to, but not including, end. If end is not sp **[⬆ back to top](#quick-links)** - ### _.random +### _.random + Produces a random number between the inclusive lower and upper bounds. If only one argument is provided a number between 0 and the given number is returned. If floating is true, or either lower or upper are floats, a floating-point number is returned instead of an integer. ```js @@ -3299,7 +3300,7 @@ Produces a random number between the inclusive lower and upper bounds. If only o ``` - #### Browser Support for `Math.random()` +#### Browser Support for `Math.random()` ![Chrome][chrome-image] | ![Edge][edge-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] :-: | :-: | :-: | :-: | :-: | :-: | From 5e1c8a27b4668b541f348c7b77fc4cec4379673d Mon Sep 17 00:00:00 2001 From: Kaspar Vollenweider Date: Fri, 4 Feb 2022 13:33:35 +0100 Subject: [PATCH 3/3] fix(header_order): reference h2 in unexpected location Since it is not a function description, I guess it is more logic to have this one at the end. --- README.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 72b0b2e..7e9ca76 100644 --- a/README.md +++ b/README.md @@ -3116,14 +3116,6 @@ Uppercases the first letter of a given string **[⬆ back to top](#quick-links)** -## Reference - -* [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference) -* [Underscore.js](http://underscorejs.org) -* [Lodash.js](https://lodash.com/docs) - -**[⬆ back to top](#quick-links)** - ## Util ### _.times @@ -3308,7 +3300,13 @@ Produces a random number between the inclusive lower and upper bounds. If only o **[⬆ back to top](#quick-links)** +## Reference +* [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference) +* [Underscore.js](http://underscorejs.org) +* [Lodash.js](https://lodash.com/docs) + +**[⬆ back to top](#quick-links)** ## Inspired by: