Skip to content

Instantly share code, notes, and snippets.

@nimamehanian
Created February 13, 2018 09:07
Show Gist options
  • Save nimamehanian/c78e0f11f570d25b00f5671d706d941d to your computer and use it in GitHub Desktop.
Save nimamehanian/c78e0f11f570d25b00f5671d706d941d to your computer and use it in GitHub Desktop.
Hacker Rank Problem
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