Skip to content

A Kotlin/Swift array utility kit that was missing in Typescript

Notifications You must be signed in to change notification settings

helcioItiyama/native-arr-kit

Repository files navigation

NativeArrKit: A Kotlin/Swift array utility kit that was missing in TypeScript.

A cross-platform array utility module for React Native and Expo, leveraging Kotlin and Swift methods such as zipping, partitioning, taking, and dropping elements.

Features

  • 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.

Usage

Importing the module

import { zip, partition, dropFirst, dropLast, dropWhile, takeFirst, takeLast, takeWhile, removeAt, shuffle } from 'native-arr-kit';

Examples

Zip

const array1 = [1, 2, 3];
const array2 = ['a', 'b', 'c'];
console.log(zip(array1, array2));
// Output: [[1, 'a'], [2, 'b'], [3, 'c']]

Partition

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

DropFirst

console.log(dropFirst([1, 2, 3, 4, 5], 2));
// Output: [3, 4, 5]

DropLast

console.log(dropLast([1, 2, 3, 4, 5], 2));
// Output: [1, 2, 3]

DropWhile

console.log(dropWhile([1, 2, 3, 4, 5], n => n < 3));
// Output: [3, 4, 5]

TakeFirst

console.log(takeFirst([1, 2, 3, 4, 5], 3));
// Output: [1, 2, 3]

TakeLast

console.log(takeLast([1, 2, 3, 4, 5], 3));
// Output: [3, 4, 5]

TakeWhile

console.log(takeWhile([1, 2, 3, 4, 5], n => n < 4));
// Output: [1, 2, 3]

RemoveAt

console.log(removeAt([1, 2, 3, 4, 5], 2));
// Output: [1, 2, 4, 5]

Shuffle

console.log(shuffle([1, 2, 3, 4, 5]));
// Output: [3, 1, 5, 2, 4]

About

A Kotlin/Swift array utility kit that was missing in Typescript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published