Skip to content

Instantly share code, notes, and snippets.

@danba340
Last active December 3, 2020 22:07
Show Gist options
  • Save danba340/b353da579019ed3698f71a675d809080 to your computer and use it in GitHub Desktop.
Save danba340/b353da579019ed3698f71a675d809080 to your computer and use it in GitHub Desktop.
const numbers = [1, 2, 3];
const sum = numbers.reduce((acc, number) => {
console.log(acc, number);
return acc + number;
}, 0);
console.log(sum);
const multiplication = numbers.reduce((acc, number) => {
console.log(acc, number);
return acc + number;
}, 1);
console.log(multiplication);
const ingredients = ["🍌", "πŸ„", "🍞", "πŸ’"];
const makeBananaBread = (ingredients) => {
return ingredients.reduce((acc, ingredient) => {
console.log(acc, ingredient)
if((acc + ingredient).includes("🍌") && (acc + ingredient).includes("🍞")) {
return "πŸ₯§"
}
else if(ingredient === "🍌" || ingredient === "🍞"){
return acc + ingredient;
}
return acc
}, "")
}
console.log(makeBananaBread(ingredients))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment