Skip to content

Instantly share code, notes, and snippets.

@LFTroya
Last active July 24, 2020 00:40
Show Gist options
  • Save LFTroya/d9838d334f7e75ba260dfd8913187444 to your computer and use it in GitHub Desktop.
Save LFTroya/d9838d334f7e75ba260dfd8913187444 to your computer and use it in GitHub Desktop.
['1-2020', '2-2020', '3-2020'].map(shortDate => {
const transaction = transactions.find(transaction => `${transaction.month}-${transaction.year}` === shortDate);
const {total_incomes, total_expenses, utility_before_taxes} = transaction.details;
return {date: shortDate, total_incomes, total_expenses, utility_before_taxes};
});
// [
// {date: '1-2020', total_incomes: 0, total_expenses: 0, utility_before_taxes: 0},
// {date: '2-2020', total_incomes: 0, total_expenses: 0, utility_before_taxes: 0},
// {date: '3-2020', total_incomes: 0, total_expenses: 0, utility_before_taxes: 0}
// ]
// Or you can transform transactions
transactions.map(transaction => {
const {total_incomes, total_expenses, utility_before_taxes} = transaction.details;
return {date: `${transaction.month}-${transaction.year}`, total_incomes, total_expenses, utility_before_taxes};
});
// Exact result but for the range
// [
// {date: '1-2020', total_incomes: 0, total_expenses: 0, utility_before_taxes: 0},
// {date: '2-2020', total_incomes: 0, total_expenses: 0, utility_before_taxes: 0},
// {date: '3-2020', total_incomes: 0, total_expenses: 0, utility_before_taxes: 0}
// ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment