Tester fonction uniqBy

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Length not cached
function uniqueBy(arr, key){
  const record = []
  const seen = {}
  for (let i = 0; i < arr.length; ++i) {
    const item = arr[i]
    const val = item[key]
    if (!seen[val]) {
      seen[val] = 1
      record.push(item)
    }
  }
}
ready
Length cached
function uniqueBy(arr, prop){
  const record = []
  const seen = {}
  for (let i = 0, len = arr.length; i < len; ++i) { // Notice the len = arr.length
    const item = arr[i]
    const val = item[prop]
    if (!seen[val]) {
      seen[val] = 1
      record.push(item)
    }
  }
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.