As simple as it may sound ,sock laundry can be a pain in the ass.
knowing what to do first ,when to do it ,and when next to make a move.
This laundry takes a lot of thinking or maybe not so much,take a deep breath ,relax you are about to do this .
In this sock Laundry Solution,a function is required to take three arguments
- An array of Cleans socks
- An array of Dirty socks
- The maximum number of washes
Pretty clear right ?
let's start with a case where number of washes is equal to zero ,this means that the dirty socks will not be washed.In this case we return only the possible number of pairs in the clean socks array.
The first step is to check for the possible number of washes
if the number of washes is less than 1,pair the array of clean socks and return count,which is equal is number of pairs .
if the number of washes is greater than 0.check if the number of washes is greater than the length of the DIRTYSOCKS array.
In this case where number of washes is greater than the length of the dirty sock array,we pair the clean and dirty socks array and return the combined pair .
The Sock Laundry Solution requires two functions
One that returns the number of pairs in a given array
and another that takes two arrays and checks for matching pairs while it increments the number of washes.
Easy right ?
Emily Gui -
Edison Pebojot(👨💻) -
How to optimize images on eleventy (11ty)
Mahmoud Ashraf -
🚀10 Trending projects on GitHub for web developers - 28th August 2020
Iain Freestone -