github.com quicksnip/snippets/javascript/array-manipulation/remove-duplicates.md at main · technoph1le/quicksnip
Find code snippets in seconds, across multiple languages. - technoph1le/quicksnip
https://quicksnip.dev/ , but with fedify.dev to create an experimental federated snippet store right from lemmy (hope that this doesn't count as spam!)
javascript/array-manipulation/remove-duplicates.md
Find code snippets in seconds, across multiple languages. - technoph1le/quicksnip
js
const removeDuplicates = (arr) => [...new Set(arr)]; // Usage: const numbers = [1, 2, 2, 3, 4, 4, 5]; removeDuplicates(numbers); // Returns: [1, 2, 3, 4, 5]
javascript/array-manipulation/partition-array.md
Find code snippets in seconds, across multiple languages. - technoph1le/quicksnip
js
const partition = (arr, callback) => arr.reduce( ([pass, fail], elem) => (callback(elem) ? [[...pass, elem], fail] : [pass, [...fail, elem]]), [[], []] ); // Usage: const numbers = [1, 2, 3, 4, 5, 6]; const isEven = (n) => n % 2 === 0; partition(numbers, isEven); // Returns: [[2, 4, 6], [1, 3, 5]]