Skip to content

Instantly share code, notes, and snippets.

@moeinrahimi
Last active November 18, 2021 19:26
Show Gist options
  • Save moeinrahimi/20b8145dfbadcacff18164a432c4ce7b to your computer and use it in GitHub Desktop.
Save moeinrahimi/20b8145dfbadcacff18164a432c4ce7b to your computer and use it in GitHub Desktop.
pure function
const R = require('ramda');
const filterFood = (food) => R.gt(food.amount, 0);
const cleaner = (day) =>
R.map((item) => R.filter(filterFood, item.foods), day.meals);
const removeZeroAmounts = (diet) => {
const dietClone = R.clone(diet);
const cleanDays = R.map(cleaner, dietClone.days);
return { ...dietClone, days: cleanDays };
};
@mohaalak
Copy link

you can make this more readable, you don't need ramda

const removeZeroAmounts = (diet) => ({ ...diet, days: diet.days.map(item => item.meals.filter(x => x > 0)) })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment