array-xtra

Extra array methods : uniq, sum, contain, flatt, remove, removeAll

Usage no npm install needed!

<script type="module">
  import arrayXtra from 'https://cdn.skypack.dev/array-xtra';
</script>

README

💨[Xtra]

Extra array methods : rand, uniq, sum, contain, flatt
badgen badgen

$ npm i array-xtra --save

Usage

import {uniq} from 'array-xtra'
// or
var {uniq} = require('array-xtra')

Or include it via jsDelivr CDN:

<script src="https://cdn.jsdelivr.net/npm/array-xtra@0.1.3/build/index.min.js"></script>
// access via object : xtra 
xtra.uniq([1, 2, 3, 1, 2]) // [1,2,3]

Methods & Examples

  • remove([], element, [startIndex]) : []
remove([1,2,3,1], 1) // [2, 3, 1]
remove(['a','b','c','a'], 'a') // ['b', 'c', 'a']
  • removeAll([], element, [startIndex]) : []
removeAll([1,2,3,1], 1) // [2, 3]
removeAll(['a','b','c','a'], 'a') // ['b', 'c']
  • rand([]) : Number|String
    return random item from an Array
rand([1, 2, 3]) // 3
rand(['a','b','c']) // 'c'
  • uniq([]) : []
uniq([1, 2, 3, 1, 2]) // [1, 2, 3]
  • sum([], [startIndex]) : Number
sum([1, 2, 3]) // 6
sum([1, 2, 3], 2) // 3
  • contain([], element, [startIndex]) : Boolean
contain([1, 2, 3, 1, 2], 2) // true
contain([1, 2, 3], 2, 2) // false
  • flatt([]) : []
flatt([1, 2, [3, [4]]]) // [ 1, 2, 3, 4 ]

Notes

  • Works both in Node.js and in the browser.
  • Supported in all old and modern browsers.
  • All pull requests are welcome, feel free.

License

MIT