Skip to content

Instantly share code, notes, and snippets.

@jpcody
Created July 23, 2011 19:35
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 jpcody/1101790 to your computer and use it in GitHub Desktop.
Save jpcody/1101790 to your computer and use it in GitHub Desktop.
// run this first on the console
var script= document.createElement('script');
script.src= 'https://raw.github.com/documentcloud/underscore/master/underscore-min.js';
document.head.appendChild(script);
// then run this
var someObj = {
config : {
groupIds : []
},
_generateGroupId : function randGen(){
var newId = Math.floor(Math.random() * 1000);
if( _(this.config.groupIds).include(newId) ){
newId = randGen.apply( this );
return newId;
} else {
this.config.groupIds.push( newId );
return newId;
}
}
};
var myArr = Array(1000).join('foo')
.split('foo')
.map(function(v, i){
return i;
}).sort(function(){
return Math.random() - 0.5;
});
myVal = myArr.pop();
myOtherVal = someObj._generateGroupId();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment