A cross-platform array utility module for React Native and Expo, leveraging Kotlin and Swift methods such as zipping, partitioning, taking, and dropping elements.
- Zip: Combine two arrays element-wise.
- Partition: Split an array into two based on a predicate.
- DropFirst: Remove the first N elements from an array.
- DropLast: Remove the last N elements from an array.
- DropWhile: Remove elements while a predicate is true.
- TakeFirst: Retrieve the first N elements from an array.
- TakeLast: Retrieve the last N elements from an array.
- TakeWhile: Retrieve elements while a predicate is true.
- RemoveAt: Remove an element at a specified index.
- Shuffle: Randomize the order of elements in an array.
import { zip, partition, dropFirst, dropLast, dropWhile, takeFirst, takeLast, takeWhile, removeAt, shuffle } from 'native-arr-kit';
const array1 = [1, 2, 3];
const array2 = ['a', 'b', 'c'];
console.log(zip(array1, array2));
// Output: [[1, 'a'], [2, 'b'], [3, 'c']]
const numbers = [1, 2, 3, 4, 5];
const [evens, odds] = partition(numbers, n => n % 2 === 0);
console.log(evens); // [2, 4]
console.log(odds); // [1, 3, 5]
// order may vary on IOS
console.log(dropFirst([1, 2, 3, 4, 5], 2));
// Output: [3, 4, 5]
console.log(dropLast([1, 2, 3, 4, 5], 2));
// Output: [1, 2, 3]
console.log(dropWhile([1, 2, 3, 4, 5], n => n < 3));
// Output: [3, 4, 5]
console.log(takeFirst([1, 2, 3, 4, 5], 3));
// Output: [1, 2, 3]
console.log(takeLast([1, 2, 3, 4, 5], 3));
// Output: [3, 4, 5]
console.log(takeWhile([1, 2, 3, 4, 5], n => n < 4));
// Output: [1, 2, 3]
console.log(removeAt([1, 2, 3, 4, 5], 2));
// Output: [1, 2, 4, 5]
console.log(shuffle([1, 2, 3, 4, 5]));
// Output: [3, 1, 5, 2, 4]