Skip to main content
added 443 characters in body
Source Link
João Silva
  • 91.8k
  • 29
  • 156
  • 158

Instead of using that large array, simply use [1,2,3,4,5].shuffle(). This way, you won't get duplicatesduplicates. But here's a function that will give you a unique array, i.e., an array without duplicates:

function unique(arr) { var result = [], map = {}; for (var i = 0; i < arr.length; i++) { var duplicate = map[arr[i]]; if (!duplicate) { result.push(arr[i]); map[arr[i]] = true; } } return result; } 

Then, just use unique(tempArray.shuffle()).

Here's a DEMO.

Instead of using that large array, simply use [1,2,3,4,5].shuffle(). This way, you won't get duplicates.

Instead of using that large array, simply use [1,2,3,4,5].shuffle(). This way, you won't get duplicates. But here's a function that will give you a unique array, i.e., an array without duplicates:

function unique(arr) { var result = [], map = {}; for (var i = 0; i < arr.length; i++) { var duplicate = map[arr[i]]; if (!duplicate) { result.push(arr[i]); map[arr[i]] = true; } } return result; } 

Then, just use unique(tempArray.shuffle()).

Here's a DEMO.

Source Link
João Silva
  • 91.8k
  • 29
  • 156
  • 158

Instead of using that large array, simply use [1,2,3,4,5].shuffle(). This way, you won't get duplicates.