0

I am formatting my data using the map function inside a method I am calling with a parameter named "period".

I need to get the keynames to be dynamic (generated by the base name + the period I am passing along to the outter function but it wont let me no matter how I try.

Can anyone guide me towards how to do it?

Here is my code

export async function EMA(candles: Candle[], period: number) {  //period should be used to generate key name below
  const input = candles.map((candle) => candle.close);
  const ema = await ta.indicators.ema.indicator([input], [period]);
  const diffLen = input.length - ema[0].length;
  const emptyArray = [...new Array(diffLen)].map((entry) => 0); //set 0  value for entriers before period
  const emaValues = [...emptyArray, ...ema[0]]; //get rsi values including 0 values

  candles = candles.map((candle, i) => ({
    ...candle,
    ema + period: { value: emaValues[i], period: period },  //Here I want the keyname to be ema200 ie.
  }));

  return candles;
}

Is this even possible to use the outter functions parameter inside the .map function and build a dynamic object key name?

BitQueen
  • 585
  • 1
  • 6
  • 20

0 Answers0