Created
February 25, 2019 18:52
-
-
Save coreyjs/25a0fabfada1512a56b5d4e37c5fbf4f to your computer and use it in GitHub Desktop.
Daily Coding Email Problem 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Given an array of integers, return a new array such that | |
| # each element at index i of the new array is the product of all the | |
| # numbers in the original array except the one at i. | |
| input = [1, 2, 3, 4, 5] | |
| input2 = [3, 2, 1] | |
| def sum_array(input) | |
| total = input.reduce(1, :*) | |
| out = [] | |
| puts "Total Value of input array: #{input}" | |
| input.each_with_index do |num, index| | |
| out[index] = (total * (num**-1)).ceil | |
| end | |
| out | |
| end | |
| puts sum_array(input).to_s | |
| puts sum_array(input2).to_s | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment