Here is my solution that doesn't pass the performance requirements. As far as I can tell it is similar to other solutions I have looked up:
function solution(A) {
let slice = A.slice(1,A.length);
let firstSliceSum = A[0];
let lastSliceSum = slice.reduce((a, b) => a + b);
let smallestValue = Math.abs(firstSliceSum-lastSliceSum);
for(let i=1;i<A.length-1;i++){
let shift = slice.shift();
firstSliceSum=firstSliceSum+shift;
lastSliceSum=lastSliceSum-shift;
let diff = Math.abs(firstSliceSum-lastSliceSum);
if(diff<smallestValue)smallestValue=diff;
}
return smallestValue;
}
It just has one for loop that iterates the elements, not counting the initial "reduce" function. I have seen similar Java solutions that are supposed to pass with 100%. Link to the challenge : https://app.codility.com/programmers/lessons/3-time_complexity/tape_equilibrium/