Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Cómo encontrar el valor mínimo y máximo para cada año para una matriz de objetos de datos de precios históricos
2800: {Date: '2022-01-14', Open: 514.48999, High: 522.570007, Low: 511.269989, Close: 520.599976, …} 2801: {Date: '2022-01-18', Open: 510.390015, High: 519.390015, Low: 504.980011, Close: 513.340027, …} 2802: {Date: '2022-01-19', Open: 516.47998, High: 528.919983, Low: 515.299988, Close: 516.580017, …} 2803: {Date: '2022-01-20', Open: 522.380005, High: 532.030029, Low: 509.640015, Close: 510.850006, …} 2804: {Date: '2022-01-21', Open: 508.5, High: 513.859985, Low: 499.269989, Close: 499.910004, …} 2805: {Date: '2022-01-24', Open: 491.070007, High: 520.429993, Low: 483.309998, Close: 519.659973, …} 2806: {Date: '2022-01-25', Open: 505.51001, High: 514.26001, Low: 500.01001, Close: 502.720001, …}

Tengo los siguientes datos de precios históricos de ADBE que abarcan más de 10 años. Estoy tratando de obtener el valor mínimo y máximo cada año de acuerdo con su fecha de informe, período que finaliza en noviembre de cada año.

Estoy tratando de obtener la salida en una matriz: [2010 min price, 2011 min price, 2012 min price ...]

 const startDate = new Date("2010-12-01"); const endDate = new Date("2022-04-30"); const data2 = data.filter(a => { const date = new Date(a.Date); return (date >= startDate && date <= endDate); }); console.log(data) function findMinMax(key) { const datas = data2.map((node) => node[key]); return { min: Math.min(...datas), max: Math.max(...datas), } } const checkit = findMinMax('Close')

Según el código, ¿cómo puedo hacerlo sin tener que cambiar la fecha de inicio y finalización de cada año solo para obtener el valor mínimo máximo?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Consulte la solución a continuación, calcula el mínimo/máximo para todos los campos en función del mes del informe.

 const data = [ { Date: "2022-01-14", Open: 100, High: 500, Low: 50, Close: 1000 }, { Date: "2021-12-05", Open: 200, High: 150, Low: 150, Close: 2000 }, { Date: "2021-10-21", Open: 300, High: 550, Low: 70, Close: 200 }, { Date: "2021-02-18", Open: 250, High: 600, Low: 10, Close: 500 }, ]; const START_REPORTING_MONTH = 11; // 11 for December const output = data.reduce((res, { Date: date, ...rest }) => { const d = new Date(date); const year = d.getFullYear(); const month = d.getMonth(); let reportingPeriod; if (month >= START_REPORTING_MONTH) { reportingPeriod = `${year}-${year + 1}`; } else { reportingPeriod = `${year - 1}-${year}`; } if (!res[reportingPeriod]) { res[reportingPeriod] = { min: { ...rest }, max: { ...rest } }; } Object.entries(rest).forEach(([k, v]) => { if (v < res[reportingPeriod].min[k]) { res[reportingPeriod].min[k] = v; } if (v > res[reportingPeriod].max[k]) { res[reportingPeriod].max[k] = v; } }); return res; }, {}); console.log(output);
 .as-console-wrapper { max-height: 100% !important; top: 0; }

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!