RSSAmplifier

(untitled) · Oct 23, 2015

How to find the balance points of an array

0
Sign in to vote or save

This site does not allow itself to be embedded. You can still read it on the original site — the toolbar below keeps your place in the directory.

A balance point is where the left side of the index is equal to the right side of the index. This function returns an array of indices of balance points. function balancePoints(array) { if ( ! Array .isArray(array)) { return []; } var totalSum = array.reduce(sum, 0 ); var leftSum = 0 ; return array.reduce( function (points, current, i) { if (i > 0 ) { leftSum += array[i - 1 ]; } var rightSum =…

Read on miguelmota.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.