JavaScript – Balance an Unbalanced Power Load

The array below contains a list of numbers that represent power load. The while loop, loops through the array and gets the sum of the array. The sum is then passed into the balance_load function so it can divide it into 3 parts such that the maximum and minimum value are as minimum as possible. What I would like to do next is write an algorithm that will distribute the available numbers(load) in the array to x, y and z such that the total values in x, y and z are very close to eachother and the sum of all three equal the sum of the entire array which in the example below is 909. The objective is to make the load as balanced as possible.

**GET SUM OF THE ARRAY AND DIVIDE IN THREE PARTS**
let x = 0;
let y = 0;
let z = 0;


function balance_load(x, n){
  let balanced_load = []
  if(x < n){
    balanced_load.push('-1')
  }else if(x % n === 0){
    for(let i=0; i<n; i++){
      balanced_load.push((x/n))
    }
  }else{
    let smallest_value = Math.floor(x/n);
    let smallest_value_count = n - (x % n)

    for(let i=0; i<n;i++){
      if(i >= smallest_value_count){
        balanced_load.push((smallest_value + 1))
      }else{
        balanced_load.push(smallest_value)
      }
    }
  }

  return balanced_load
}



let total = 0;


let array = [50,50,25,167,167,50,25,50,75,75,25,50,25,50,25]


for(let i of array){
  total += i
}
let balance = balance_load(total,3)

console.log(balance)
**EXAMPLE OF THE TYPE OF OUTPUT I AM LOOKING FOR AFTER GETTING SUM OF THE ARRAY AND DIVIDING IT BY THREE**

//x=317 (50 + 167 + 50 + 50)
//y=292 (167 + 75 +25 + 25)
//z=300 (50 + 25 + 50 + 25 + 75 + 50 + 25)
//x + y + z = 909//which is  the total