JavaScript: Best Way to return true if found values repeated in an array -
possible duplicate:
easiest way find duplicate values in javascript array
let's have array thousands of elements ,
i want return true if there 2 or more elements same value.
i know can run for loop , check on every pair of elements find answer.
but there faster way? , what's best way?
this element distinctness problem. can read it, 1000 elements, optimizations not worth it.
if want optimize it, can push elements hash table , check if collisions duplicates. give o(n) on average (amortized), o(n^2) in worst case.
Comments
Post a Comment