I would like to optimize the below code as it seems like too many steps. The code does work, however I would like to see if there is a better way of doing it. I basically want to take the first X elements and last X elements from the shipmentTracings array. Is there a way to optimize that part?
Also, I am deriving the elements I want on the left and right side of the array based on numberOfTracings / 2. For an odd number, I am rounding down, but you can see I am using the paddingRight to use the remainder, if any. Is there also a better way to do that?
const numberOfTracings = environment.shipmentTracingMarkerLimit - this.shipmentTracking.shipmentStops.length; // i.e. 7
const paddingLeft = Math.floor(numberOfTracings / 2);
const paddingRight = numberOfTracings - paddingLeft * 2; //i am doing this because I want to use that extra array spot to be padded. It
const myFirstArr = this.shipmentTracking.shipmentTracings.slice(0, paddingLeft);
const myFirstArr2 = this.shipmentTracking.shipmentTracings.slice(-(paddingLeft + paddingRight));
const myFirstArr3 = myFirstArr.concat(myFirstArr2);
myFirstArr3.forEach((shipmentTracing) => this.createRouteMarkerForTracing(shipmentTracing));
[...arr.slice(0, x), ...arr.slice(-x)];? Agree, need expected input/output.const myFirstArr3 = [...this.shipmentTracking.shipmentTracings.slice(0, paddingLeft), ...this.shipmentTracking.shipmentTracings.slice(-(paddingLeft + paddingRight))];