Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

g00glen00b commented Mar 2, 2015

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