NRuby
19 строк · 632.0 Байт
1a = [0, 4, 7, 10, 12]
2a.bsearch {|x| x >= 4 } # => 4
3a.bsearch {|x| x >= 6 } # => 7
4a.bsearch {|x| x >= -1 } # => 0
5a.bsearch {|x| x >= 100 } # => nil
6
7r = (0...a.size)
8r.bsearch {|i| a[i] >= 4 } #=> 1
9r.bsearch {|i| a[i] >= 6 } #=> 2
10r.bsearch {|i| a[i] >= 8 } #=> 3
11r.bsearch {|i| a[i] >= 100 } #=> nil
12r = (0.0...Float::INFINITY)
13r.bsearch {|x| Math.log(x) >= 0 } #=> 1.0
14
15a = [0, 4, 7, 10, 12]
16a.map {|x| x >= 4 } # => [false, true, true, true, true]
17a.map {|x| x >= 6 } # => [false, false, true, true, true]
18a.map {|x| x >= -1 } # => [true, true, true, true, true]
19a.map {|x| x >= 100 } # => [false, false, false, false, false]