this post was submitted on 03 Jan 2025
4 points (100.0% liked)

Quicksnip

1 readers
6 users here now

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!)

founded 1 month ago
MODERATORS
 

title: Partition Array description: Splits an array into two arrays based on a callback function. author: Swaraj-Singh-30 tags: array,partition,reduce


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]]
top 1 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 1 month ago

Hey there I am testing out how api works of lemmy and to integrate this here , I might delete this afterwards since I want this , to be an alternative to using github for quicksnip.

Happy new year!