static/js/ari.js
/**
 * Return array of unique elements from the input array.
 * @function unique
 * @param {number[]} arr - the input array
 * @param {boolean} returnInv - if true, return the indices of of the unique array, default to false
 * @return {number[]} the unique array and optional indices of unique array
 */
Return array of unique elements from the input array.
@function unique
@param {number[]} arr - the input array
@param {boolean} returnInv - if true, return the indices of of the unique array, default to false
@return {number[]} the unique array and optional indices of unique array
Return array of unique elements from the input array . @function unique @param { number [] } arr - the input array @param { boolean } returnInv - if true return the indices of of the unique array default to false @return { number [] } the unique array and optional indices of unique array
function unique(arr, returnInv=false) {
  let res = Array.from(new Set(arr));
  if (!returnInv) {
    return res;
  } else {
    let inv = Array(arr.length).fill();
    for (let i = 0; i < arr.length; i++) {
      for (let j = 0; j < res.length; j++) {
        if (arr[i] === res[j]) {
          inv[i] = j;
        }
      }
    }
    return [res, inv];
  }
}
function unique ( arr , returnInv = false ) { let res = Array . from ( new Set ( arr ) ) ; if ( ! returnInv ) { return res ; } else { let inv = Array ( arr . length ) . fill ( ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { for ( let j = 0 ; j < res . length ; j ++ ) { if ( arr [ i ] === res [ j ] ) { inv [ i ] = j ; } } } return [ res , inv ] ; } }
Return array of unique elements from the input array.
Return array of unique elements from the input array .