Skip to content

Instantly share code, notes, and snippets.

@nbar1
Created March 2, 2015 02:49
Show Gist options
  • Save nbar1/6e7e0710bbe620c49b15 to your computer and use it in GitHub Desktop.
Save nbar1/6e7e0710bbe620c49b15 to your computer and use it in GitHub Desktop.
socks.js
function wash(socks) {
var socksYouHave = [];
var sockSizes = ['small', 'medium', 'large'];
socks.forEach(function(sock) {
// Weird socks never survive
if(sockSizes.indexOf(sock) === -1) return;
// One in ten socks never make it out alive
if(Math.floor(Math.random() * 10) === 0) return;
// Some socks just change
if(Math.floor(Math.random() * 10) < 4) {
socksYouHave.push(sockSizes[Math.floor(Math.random() * sockSizes.length)]);
return;
}
socksYouHave.push(sock);
});
return socksYouHave;
}
console.log(wash([
'medium',
'medium',
'medium',
'medium',
'medium',
'medium',
'medium',
'medium',
'medium',
'medium',
'medium',
'medium',
'medium',
'medium',
'medium',
'medium',
'medium',
'medium',
]));
@g00glen00b
Copy link

After 20-30 times (usually) you will have to buy new socks D:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment