static/js/numeric.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 the unique
 * array, default to false
 * @return {number[]} the unique array and optional indices of unique array
 * @see numpy.unique
 */
Return array of unique elements from the input array.
Return array of unique elements from the input array .
function unique(arr, returnInv=false) {
  const n = arr.length;
  const res = Array.from(new Set(arr));
  if (!returnInv) return res;
  const m = res.length;
  let inv = Array(n).fill();
  let j;
  for (let i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (arr[i] === res[j]) {
        inv[i] = j;
      }
    }
  }
  return [res, inv];
}
function unique ( arr , returnInv = false ) { const n = arr . length ; const res = Array . from ( new Set ( arr ) ) ; if ( ! returnInv ) return res ; const m = res . length ; let inv = Array ( n ) . fill ( ) ; let j ; for ( let i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; 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 .