static distinctBy(array, fn) {
    if (console) {
      console.assert(array)
      console.assert(fn)
    }
    let idx = {}
    let res = []
    for (let i = 0; i < array.length; i++) {
      let element = array[i]
      let r = fn(element)
      if (!idx[r]) {
        idx[r] = true
        res.push(element)
      }
    }
    return res
  }
/**
   * Keep only distinct values according to a function apply to the
   * array elements
   *
   * example 1 (normal distinct using identity function):
   *  distinctBy(["a", "b", "b"], s => s)
   *    => ["a", "b"]
   *
   * example 2 (distinct by object property value):
   *  distinctBy([{id: 1, k1: "v1"}, {id: 1, k2: "v2"}], o => o.id)
   *    => [{id: 1, k1: "v1"}]
   */
Keep only distinct values according to a function apply to the
array elements




Keep only distinct values according to a function apply to the array elements
static distinctBy(array, fn) {
    if (console) {
      console.assert(array)
      console.assert(fn)
    }
    let idx = {}
    let res = []
    for (let i = 0; i < array.length; i++) {
      let element = array[i]
      let r = fn(element)
      if (!idx[r]) {
        idx[r] = true
        res.push(element)
      }
    }
    return res
  }
static distinctBy ( array , fn ) { if ( console ) { console . assert ( array ) console . assert ( fn ) } let idx = { } let res = [ ] for ( let i = 0 ; i < array . length ; i ++ ) { let element = array [ i ] let r = fn ( element ) if ( ! idx [ r ] ) { idx [ r ] = true res . push ( element ) } } return res }
Keep only distinct values according to a function apply to the
 array elements
Keep only distinct values according to a function apply to the array elements