# How to split arrays

Please how can i split an array such that the sum of numbers on the left side is equal to the sum on the right side?

why don’t you try it yourself first?

it needs a few steps, so maybe try first with pen and paper writing down pseudocode, breaking down the task in its smallest components
things to consider:

• it asks for sums, you need ways to sum together only parts of the array
• you need to consider all possible ways to split the array in two parts

also, a great help in helping you to check your code is to show all instructions

Given a non-empty array, if there is a place to split the array so that the sum of the numbers on one
side is equal to the sum of the numbers on the other side return the length of the two arrays as an array but
if there is no place to split the array, return -1

canBalance([1, 1, 1, 2, 1]) → [3,2]
canBalance([2, 1, 1, 2, 1]) → -1
canBalance([10, 10]) → [1,1]

left =0;
right = sum of left;

if (left == right) {
return true;
} else {
return false;
}

I need help seriously.

we are not here to do your homework
try something yourself first
show what you have tried
not necessarily javascript, even some pseudocode

I understand that too. just need a direction.

what kind of direction you need?
we have no idea of your level so we can’t give hints appropriately
if you show what you have tried instead we have a starting point

Hi @cheerfulkechem, you can start by looking at the array documentation on MDN. Among the various methods there will be those that you need to divide the array.
Of course before that you would still need to implement the logic to find the index where the array will be separated in two parts.
As ieahleen said, it can greatly help to work your ideas on paper first.