refactor: do processing in one loop

This commit is contained in:
Lemuel 2022-03-11 19:41:21 +08:00
parent 7362e8d5e2
commit 910768f531

View File

@ -4,10 +4,10 @@ export default function heikinAshiDataset(columns: string[], data: Array<number[
const highIdx = columns.indexOf('high');
const lowIdx = columns.indexOf('low');
return data.map((original, idx, candles) => {
// Prevent mutation of original data
const dataCopy = data.map((original) => original.slice());
const candle = original.slice();
return dataCopy.map((candle, idx, candles) => {
if (idx === 0) {
const close = (candle[openIdx] + candle[highIdx] + candle[lowIdx] + candle[closeIdx]) / 4;
const open = (candle[openIdx] + candle[closeIdx]) / 2;