Skip to content

Instantly share code, notes, and snippets.

@hiun
Created December 17, 2014 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiun/4b05614c3b9405e9033d to your computer and use it in GitHub Desktop.
Save hiun/4b05614c3b9405e9033d to your computer and use it in GitHub Desktop.
'use strict';
(function () {
var i;
var obj = {};
for (i = 0; i < 200; i++) {
var arr = [
'red',
'orange',
'yellow',
'green',
'blue',
'darkblue',
'violet'
];
var len = arr.length;
var period = 1 / len;
var rand = Math.random();
var r = (rand > period ? Math.floor(rand / period) : 0);
if (obj[r] === undefined) {
obj[r] = 0;
} else {
//console.log(obj[r]++);
obj[r] = ++obj[r];
}
}
console.log(obj);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment