Created
March 2, 2015 02:49
-
-
Save nbar1/6e7e0710bbe620c49b15 to your computer and use it in GitHub Desktop.
socks.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | |
])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After 20-30 times (usually) you will have to buy new socks D: