2.0.6 • Published 5 months ago

@henrik-dmg/swifty-array-helpers v2.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Array Helpers for JavaScript

npm npm

What is this?

A collection of functions for working with arrays inspired by the methods that are available in Swift

Usage

Import

You need to import the methods first. Example:

// ES6 module
import '@henrik-dmg/swifty-array-helpers'

// node.js
require('@henrik-dmg/swifty-array-helpers')

firstIndex

Finds the index of the first element matching the predicate. Example:

const array = [5, 3, 7, 12]
const index = firstIndex(array, x => x <= 4) // 1

firstWhere

Finds the first element matching the predicate (similar to firstIndex). Example:

const array = [5, 3, 7, 12]
const firstElementMatchingPredicate = firstWhere(array, x => x <= 4) // 3

compactMap

Maps all values, filtering null or undefined values out Example:

const array = [
  { name: 'Henrik' },
  { name: 'Henrik', lastName: 'Panhans' },
  { name: 'Henrik' },
  { name: 'Henrik' }
]
const lastNames = compactMap(array, value => value.lastName) // ["Panhans"]
2.0.6

5 months ago

2.0.5

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago