Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

skava / chain-able-deps   js

Repository URL to install this package:

Version: 6.0.4 

/ src / array / uniq.ts

/* eslint prefer-includes/prefer-includes: "OFF" */

/**
 * @desc use in array.filter(uniq) to de-dupe values using indexOf
 * @since 0.1.0
 * @memberOf array
 *
 * @param  {*} value value in array iteration
 * @param  {number} index current index
 * @param  {Array} arr array being iterated, `thisArg` when using .filter
 * @return {Array} de-duped/uniqued array
 *
 * @func
 * @name uniq
 * @alias unique
 *
 * {@link https://github.com/lodash/lodash/blob/master/uniq.js lodash-uniq}
 * {@link https://github.com/mobxjs/mobx/blob/master/src/utils/utils.ts#L58 mobx-uniq}
 * {@link https://github.com/jashkenas/underscore/blob/master/underscore.js#L559 underscore-uniq}
 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter mozilla-array-filter}
 * @see {@link mozilla-array-filter}
 * @see {@link underscore-uniq}
 * @see {@link mobx-uniq}
 * @see {@link lodash-uniq}
 *
 * @example
 *
 *   var list = [
 *      1, 2, 3,
 *      1, 2, 3,
 *      1, 2, 3
 *   ]
 *
 *   list.filter(uniq)
 *   //=> [1, 2, 3]
 *
 */
export default <Type = any>(value: Type, index: number, arr: Type[]) =>
  arr.indexOf(value) === index