Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
If it's be me will make it null, don't wear any so you don't have a tension of sorting.
-
ridecar23818y@RamChandra But then surely when trying to call any sock related method you would have a NullRef and have to deal with null propagation.
-
@ridecar2 thinking about that situation, maybe creating a new object shoes with socks declared as final so you don't have to pick one.
-
monr0e12458yForeach (Sock sock in socks)
{
If (sock.pattern.hasMatch(patternArray))
{
int pair = patternArray.Match(sock);
patterArray.moveToDrawer[pair]
}
else
{
patternArray.Add(sock)
}
}
1: yes, there is a function for "hasMatching"
2: yes, it could be more efficient, but this way its a more accurate representation of how I actually sort socks.
3: why would you wear odd socks? That's just annoying. -
Sleepsort by hash of pattern. Human won't act faster than that anyway..^^
But if you want it efficient, call
function getSock() {
const i = Math.floor(Math.random() * socks.length);
return socks.splice(i, 1)[0];
}
Twice.😋
Related Rants
Let's see how many of us can use programming skill outside in real world.
Pair socks from a pile efficiently?
undefined
programming
skill
question