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


Keywords
flat, sum, uniq, contain, random, remove, extra, array, methods, utility, nodejs, javascript, browser, umd
License
MIT
Install
npm install array-xtra@0.1.3

Documentation

💨[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