Advertisement
maneesf

Untitled

Feb 22nd, 2021
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const subcategories = [
  2.   {
  3.     "sub_Details":{
  4.       "id":76,
  5.       "name":"testrent",
  6.       "category_id":7,
  7.       "user_id":"10"
  8.     },
  9.     "amount":2388
  10.   },
  11.   {"sub_Details":{"id":78,"name":"fdfdf","category_id":7,"user_id":"10"},"amount":23},{"sub_Details":{"id":71,"name":"Just for checking1","category_id":7,"user_id":"10"},"amount":100},{"sub_Details":{"id":79,"name":"testsubcat","category_id":7,"user_id":"10"},"amount":65},{"sub_Details":{"id":80,"name":"testsubcat","category_id":7,"user_id":"10"},"amount":65},{"sub_Details":{"id":81,"name":"finaltest","category_id":7,"user_id":"10"},"amount":56333},{"sub_Details":{"id":82,"name":"finaltest","category_id":7,"user_id":"10"},"amount":52},{"sub_Details":{"id":84,"name":"abc","category_id":7,"user_id":"10"},"amount":89},{"sub_Details":{"id":83,"name":"abc","category_id":7,"user_id":"10"},"amount":89},{"sub_Details":{"id":85,"name":"roomrent","category_id":7,"user_id":"10"},"amount":69},{"sub_Details":{"id":86,"name":"roomrent","category_id":7,"user_id":"10"},"amount":69},{"sub_Details":{"id":87,"name":"trr","category_id":7,"user_id":"10"},"amount":23},{"sub_Details":{"id":88,"name":"sub","category_id":7,"user_id":"10"},"amount":26},{"sub_Details":{"id":90,"name":"testrent2","category_id":7,"user_id":"10"},"amount":22},{"sub_Details":{"id":91,"name":"Ss","category_id":7,"user_id":"10"},"amount":34},{"sub_Details":{"id":92,"name":"test1","category_id":7,"user_id":"10"},"amount":188},{"sub_Details":{"id":93,"name":"Test 3","category_id":7,"user_id":"10"},"amount":500},{"sub_Details":{"id":94,"name":"test1","category_id":7,"user_id":"10"},"amount":188},{"sub_Details":{"id":95,"name":"Teste","category_id":7,"user_id":"10"},"amount":25},{"sub_Details":{"id":96,"name":"te","category_id":7,"user_id":"10"},"amount":3},{"sub_Details":{"id":97,"name":"Ee","category_id":7,"user_id":"10"},"amount":21},{"sub_Details":{"id":65,"name":"Mortgage","category_id":7,"user_id":"10"},"amount":56},{"sub_Details":{"id":66,"name":"Home & Auto Insurance","category_id":7,"user_id":"10"},"amount":0},{"sub_Details":{"id":67,"name":"Real Estate Tax","category_id":7,"user_id":"10"},"amount":0},{"sub_Details":{"id":68,"name":"Car Payment","category_id":7,"user_id":"10"},"amount":0},{"sub_Details":{"id":69,"name":"Gasoline","category_id":7,"user_id":"10"},"amount":56},{"sub_Details":{"id":70,"name":"Utilities","category_id":7,"user_id":"10"},"amount":1000},{"sub_Details":{"id":72,"name":"Grocery","category_id":7,"user_id":"10"},"amount":5000},{"sub_Details":{"id":73,"name":"Phone","category_id":7,"user_id":"10"},"amount":0},{"sub_Details":{"id":111,"name":"Ert","category_id":7,"user_id":"10"},"amount":89},{"sub_Details":{"id":112,"name":"new","category_id":7,"user_id":"10"},"amount":799},{"sub_Details":{"id":113,"name":"teat34","category_id":7,"user_id":"10"},"amount":2000},{"sub_Details":{"id":114,"name":"carpremium","c]ategory_id":7,"user_id":"10"},"amount":2300}
  12. ]
  13.  
  14. const categories = [
  15.   {
  16.     "id":25,
  17.     "title":"Take Home Pay",
  18.     "value":7000,"created_at":"2021-02-22T11:35:54.324Z","updated_at":"2021-02-22T11:35:54.324Z","account_id":10
  19.   },
  20.   {"id":28,"title":"Discretionary","value":94270,"created_at":"2021-02-22T12:13:48.968Z","updated_at":"2021-02-22T12:13:48.968Z","account_id":10},{"id":26,"title":"necessity_expense","value":71672,"created_at":"2021-02-22T11:38:28.986Z","updated_at":"2021-02-22T12:20:59.071Z","account_id":10}
  21. ]
  22.  
  23. const getCategories = () => {
  24.   const array = categories.map(cat => {
  25.     const subcategories1 = subcategories.filter(sub => (sub.sub_Details.category_id == cat.id));
  26.  
  27.     return {
  28.       id: cat.id,
  29.       categoryName: cat.title,
  30.       subCategory: subcategories1,
  31.       amount: cat.value
  32.     }
  33.   });
  34.   return array;
  35. }
  36.  
  37. // const output = [
  38. //   {
  39. //     id: '95',
  40. //     categoryName: 'necessity',
  41. //     subCategory: [{id: '1', name: 'Sub Item 1'}],
  42. //     amount: 200
  43. //   }
  44. // ]
  45.  
  46. console.log(getCategories());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement