Created
February 13, 2018 09:07
-
-
Save nimamehanian/c78e0f11f570d25b00f5671d706d941d to your computer and use it in GitHub Desktop.
Hacker Rank Problem
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
const data = [6, 5, 8, 4, 7, 10, 9]; | |
const daysTillPlantDeath = (toxicities, daysElapsed) => { | |
const livingPlants = toxicities.filter((poisonLevel, idx) => ( | |
idx === 0 || (idx > 0 && poisonLevel <= toxicities[idx - 1]) | |
)); | |
return livingPlants.join('') === toxicities.join('') ? | |
daysElapsed : daysTillPlantDeath(livingPlants, daysElapsed + 1); | |
}; | |
daysTillPlantDeath(data, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment