You are viewing a single comment's thread. Return to all comments →
My solution in ruby
def plusMinus(arr) counters = { negatives: 0, positives: 0, zero: 0, fraction_val: 1.0 / arr.length } arr.each do |num| if num == 0 counters[:zero] = counters[:zero] + 1 elsif num > 0 counters[:positives] = counters[:positives] + 1 else counters[:negatives] = counters[:negatives] + 1 end end puts format('%.6f', (counters[:fraction_val] * counters[:positives])) puts format('%.6f', (counters[:fraction_val] * counters[:negatives])) puts format('%.6f', (counters[:fraction_val] * counters[:zero])) end
Seems like cookies are disabled on this browser, please enable them to open this website
Plus Minus
You are viewing a single comment's thread. Return to all comments →
My solution in ruby