Skip to content

Instantly share code, notes, and snippets.

@jlcarrascof
Last active September 22, 2023 13:50
Show Gist options
  • Save jlcarrascof/ae67cc78f1e0251d94f9412a215b4535 to your computer and use it in GitHub Desktop.
Save jlcarrascof/ae67cc78f1e0251d94f9412a215b4535 to your computer and use it in GitHub Desktop.
Binary Tree Challenge - 22-09-2023
function leftmostNodesSum(array) {
let sum = 0;
let index = 0;
while (index < array.length && array[index] !== 0) {
sum += array[index];
index = 2 * index + 1;
}
return sum;
}
console.log(leftmostNodesSum([2, 7, 5, 2, 6, 0, 9]))
// => 11
module.exports = leftmostNodesSum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment