From 08ff67255a9cb4ad925d3fbe2e9931453cf79a96 Mon Sep 17 00:00:00 2001 From: "Pimm \"de Chinchilla\" Hogeling" Date: Tue, 2 Jan 2024 09:54:08 +0100 Subject: [PATCH] Updated readme to take advantage of the existence of [].toSorted. --- readme-nl.md | 5 +++-- readme.md | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/readme-nl.md b/readme-nl.md index 5197e68..165d80e 100644 --- a/readme-nl.md +++ b/readme-nl.md @@ -17,7 +17,7 @@ Stel je voor dat we deze array van getallen sorteren, vertegenwoordigd als strin ``` `'12'` zou voor `'3.14'` worden geplaatst als we sorteren zonder vergelijkfunctie, dus zo een functie is vereist: ```javascript -['12', '1', '3.14'].sort((a, b) => parseFloat(a) - parseFloat(b)); +['12', '1', '3.14'].toSorted((a, b) => parseFloat(a) - parseFloat(b)); ``` Dat werkt! @@ -63,7 +63,7 @@ const sortedArray = mapSort( ## Opmerkingen -* In tegenstelling tot [`[].sort`][mdn-sort], **sorteert deze bibliotheek niet _in-place_**. Er wordt een nieuwe, gesorteerde array teruggegeven. De originele array wordt niet beïnvloed. +* Deze bibliotheek sorteert niet _in-place_, en lijkt daarmee meer op [`[].toSorted`][mdn-tosorted] dan [`[].sort`][mdn-sort]. * Deze bibliotheek sorteert [waarschijnlijk][stable-sorting] stabiel. # Licentie (X11/MIT) @@ -76,5 +76,6 @@ The above copyright notice and this permission notice shall be included in all c **The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.** +[mdn-tosorted]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted [mdn-sort]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/sort [stable-sorting]: https://github.com/Pimm/mapsort/blob/master/documentation/stable-sorting-nl.md \ No newline at end of file diff --git a/readme.md b/readme.md index dff4ced..e0da32b 100644 --- a/readme.md +++ b/readme.md @@ -17,7 +17,7 @@ Imagine we are sorting this array of numbers, represented as strings: ``` Sorting them with no compare function would place `'12'` before `'3.14'`, so we need such a function: ```javascript -['12', '1', '3.14'].sort((a, b) => parseFloat(a) - parseFloat(b)); +['12', '1', '3.14'].toSorted((a, b) => parseFloat(a) - parseFloat(b)); ``` This works! @@ -63,7 +63,7 @@ const sortedArray = mapSort( ## Notes -* Contrary to [`[].sort`][mdn-sort], this library **does not sort in-place**. It returns a new, sorted array. The original array is left untouched +* This library does not sort in-place, making it more similar to [`[].toSorted`][mdn-tosorted] than [`[].sort`][mdn-sort]. * This library [probably][stable-sorting] performs stable sorting. # License (X11/MIT) @@ -76,5 +76,6 @@ The above copyright notice and this permission notice shall be included in all c **The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.** +[mdn-tosorted]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted [mdn-sort]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/sort [stable-sorting]: https://github.com/Pimm/mapsort/blob/master/documentation/stable-sorting.md \ No newline at end of file