Home > Enterprise >  How can I refactor this code in javascript?
How can I refactor this code in javascript?

Time:01-08

I have this code and I need to refactor that

I tried creating a new function and passing it through reduce but It doesn't work

function fx(n) {
  let d= (new Array(n 1)).join('x').split('').reduce((d,v,i)=>{
  let J=2*i 1 (i&1)
  return d  = J (J 1-2*i 1)
  },-1-Math.floor(n/2) * 2);
  return d-(n-2);
};

CodePudding user response:

This is what it should be doing.

const squareIncrement = number => Math.pow(Math.abs(number)   1, 2);
  •  Tags:  
  • Related