creation of collections of unique values without set in js code example
Example 1: how to get unique values from array in javascript without duplicate value
function uniqueArray2(arr) {
var a = [];
for (var i=0, l=arr.length; i<l; i++)
if (a.indexOf(arr[i]) === -1 && arr[i] !== '')
a.push(arr[i]);
return a;
}
Example 2: how to create an array with unique values
import java.util.Random;
public class GenRandArray {
static Random rand = new Random();
public static void fillInt( int[] fillArray ) {
rand.setSeed(System.currentTimeMillis());
for(int i = 0; i < fillArray.length; i++)
{
fillArray[i]= rand.nextInt();
for (int j = 0; j < i; j++)
{
if (fillArray[i] == fillArray[j])
{
i--;
}
}
}
}
}