项目作者: leohmoraes

项目描述 :
A partir de datas e valores, obter a soma de valores separados por décadas / solution of question in whatsapp From dates and values, get the sum of values separated by decades
高级语言: JavaScript
项目地址: git://github.com/leohmoraes/sum-of-items-grouped-by-decade.git


A partir de datas e valores, obter a soma de valores separados por décadas

From dates and values, get the sum of values separated by decades

  1. // input data
  2. var years = [
  3. { year: 1994, qty: 2 },
  4. { year: 1995, qty: 1 },
  5. { year: 1999, qty: 3 },//6
  6. { year: 2000, qty: 5 },
  7. { year: 2001, qty: 2 },
  8. { year: 2002, qty: 2 },
  9. { year: 2003, qty: 1 },//10
  10. { year: 2019, qty: 5 },
  11. { year: 2010, qty: 7 },
  12. { year: 2011, qty: 1 },
  13. { year: 2012, qty: 1 },
  14. { year: 2019, qty: 2 },//16
  15. { year: 2020, qty: 5 },
  16. { year: 2021, qty: 6 },
  17. { year: 2021, qty: 7 },
  18. { year: 2021, qty: 3 }//21
  19. ];
  20. // output data
  21. results {
  22. '1990': { total: 6 },
  23. '2000': { total: 10 },
  24. '2010': { total: 16 },
  25. '2020': { total: 21 }
  26. }