Guest User

Untitled

a guest
Dec 12th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const dates = [
  2.   {value: 'Jul 19'},
  3.   {value: 'Aug 19'},
  4.   {value: 'Sep 19'},
  5.   {value: 'Oct 19'},
  6.   {value: 'Nov 19'},
  7.   {value: 'Dec 19'},
  8.   {value: 'Jan 20'},
  9. ];
  10.  
  11. function randomDelta() {
  12.   return Math.floor(Math.random() * Math.floor(10)) * 50;
  13. }
  14.  
  15. function getActualSpent(budget) {
  16.   if (isNaN(budget)) {
  17.     return randomDelta();
  18.   } else {
  19.     return budget + randomDelta();
  20.   }
  21. }
  22.  
  23. const newCampaigns = campaigns.map(c => {
  24.   const {actualSpent} = c;
  25.   const budgets = dates.map(({value, realIndex}, index) => ({
  26.     actualSpent: getActualSpent(actualSpent),
  27.     realIndex: index + 1,
  28.     value,
  29.   }));
  30.   console.log({
  31.     ...c,
  32.     budget: budgets
  33.   });
  34.   return {
  35.     ...c,
  36.     budget: budgets
  37.   }
  38. });
Advertisement
Add Comment
Please, Sign In to add comment