Question: I have an array of 5 numbers and will like to select 'ANY 3' numbers randomly  

from my array to produce the result below. I've looked and can't find a code  

that will reproduce the exact results. I was thinking a for loo' with a  

function will be the best bet but how do I go about it, any help, (JavaScript,  

Java, php) will be be appreciated please 

```
var myArray = ["1","2","3","4","5"];  
var result = myArray.slice(); 

for (i=0; i < result; i++) {
  console.log(myArray[i]);
}

Results:
1 2 3
1 2 4
1 2 5
1 3 4
1 3 5
1 4 5
2 3 4
2 3 5
2 4 5
3 4 5

```

Answer: 
Try with something like this:

```
function groupBy(collection, property) {
    var i = 0, val, index,
        values = [], result = [];
    for (; i < collection.length; i++) {
        val = collection[i][property];
        index = values.indexOf(val);
        if (index > -1)
            result[index].push(collection[i]);
        else {
            values.push(val);
            result.push([collection[i]]);
        }
    }
    return result;
}

var obj = groupBy(list, "group");

```

Keep in mind that `Array.prototype.indexOf` isn't defined in IE8 and older, but there are common polyfills for that.
I tried to use the answer marked as accepted, but noticed that there were elements missing in some groups, depending on the type of property being evaluated. This is a solution derived from that answer:

```
function groupBy(collection, property) {
  var i = 0, values = [], result = [];
  for (i; i < collection.length; i++) {
    if(values.indexOf(collection[i][property]) === -1) {
      values.push(collection[i][property]);
      result.push(collection.filter(function(v) { return v[property] === collection[i][property] }));
    }
  }
  return result;
}
var obj = groupBy(list, "group");

```