@johngw/array
TypeScript icon, indicating that this package has built-in type declarations

3.3.2 • Public • Published

@johngw/array

filterMap

Filters and maps an array in 1 loop

filterMap(
  [1, 2, 3, 4, 5, 6, 7, 8, 9],
  (x) as is number => x > 5,
  (x) => `${x} bottles`
)
/*
  [
    '6 bottles',
    '7 bottles',
    '8 bottles',
    '9 bottles',
  ]
*/

filterReduce

Filters and reduces an array in 1 loop

filterReduce(
  [1, 2, 3, 4, 5, 6, 7, 8, 9],
  0,
  (_, x) => x < 5,
  (sum, x) => sum + x
)
// 10

Builder

Performant array builder

This is used internally to build arrays. It performs 3x faster than just appending items to array with undefined length.

const builder = new Builder<number>(10_000)

for (let i = 0; i < 10_000; i++) {
  builder.add(i)
}

builder.finish()
// [0, 1, 2, 3, ..., 9999]

Readme

Keywords

none

Package Sidebar

Install

npm i @johngw/array

Weekly Downloads

209

Version

3.3.2

License

MIT

Unpacked Size

17.8 kB

Total Files

39

Last publish

Collaborators

  • johngeorgewright