You are viewing a single comment's thread. Return to all comments →
JavaScript Soution:
function equalStacks(h1, h2, h3) { let h1Total = h1.reduce((a, c) => a + c); let h2Total = h2.reduce((a, c) => a + c); let h3Total = h3.reduce((a, c) => a + c); function checkEquality(one, two, three) { if (one === two && two === three) { return true; } return false; } while (!checkEquality(h1Total, h2Total, h3Total)) { let numberToSubtract = 0; if (h1Total >= h2Total && h1Total >= h3Total) { numberToSubtract = h1.shift(); h1Total -= numberToSubtract; } else if (h2Total >= h1Total && h2Total >= h3Total) { numberToSubtract = h2.shift(); h2Total -= numberToSubtract; } else if (h3Total >= h1Total && h3Total >= h1Total) { numberToSubtract = h3.shift(); h3Total -= numberToSubtract; } } return h1Total; }
Seems like cookies are disabled on this browser, please enable them to open this website
Equal Stacks
You are viewing a single comment's thread. Return to all comments →
JavaScript Soution: