Skip to content

Instantly share code, notes, and snippets.

@mrowa44
Created January 6, 2018 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrowa44/bec5835c86f3df326688d68a981711dd to your computer and use it in GitHub Desktop.
Save mrowa44/bec5835c86f3df326688d68a981711dd to your computer and use it in GitHub Desktop.
const bees = [2, 4, 5, 6, 1, 3, 2, 4];
function countAges() {
// 1-3
let firstLifeStage = 0;
// 4-6
let secondLifeStage = 0;
bees.forEach((beeAge) => {
if (beeAge >= 1 && beeAge < 3) {
firstLifeStage += 1;
} else if (beeAge >= 3 && beeAge < 6) {
secondLifeStage += 1;
} else {
// etc.
}
});
return {
firstStageCount: firstLifeStage,
secondStageCount: secondLifeStage,
};
}
const a = countAges();
console.log('result: ', a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment