Skip to content

Instantly share code, notes, and snippets.

@venelrene
Created January 3, 2020 17:50
Show Gist options
  • Select an option

  • Save venelrene/8e633d0f41b5d88522fe97cfe2c8064f to your computer and use it in GitHub Desktop.

Select an option

Save venelrene/8e633d0f41b5d88522fe97cfe2c8064f to your computer and use it in GitHub Desktop.
For inputArray = [5, 1, 2, 3, 0, 1, 5, 0, 2], the output should be 11. The answer was obtained as 5 + 1 + 2 + 3 = 11.
def house_numbers_sum(input_array)
input_array.take_while { |n| n > 0 }.sum
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment