How many negative numbers? : inject « Range « Ruby






How many negative numbers?


(-2..10).inject(0) {|num, x| x<0 ? num+1 : num }  # => 2

 

Related examples in the same category

1.Inject a range