- map
- map
Transform with map
examples/arrays/map.cr
numbers = [2, -3, 4, -5] puts numbers puts "" doubles = numbers.map do |num| num*2 end puts doubles puts numbers puts "" triples = numbers.map { |num| num*3 } puts triples puts numbers puts "" abs = numbers.map &.abs puts abs puts numbers puts "" abs = numbers.map! &.abs puts abs puts numbers
[2, -3, 4, -5] [4, -6, 8, -10] [2, -3, 4, -5] [6, -9, 12, -15] [2, -3, 4, -5] [2, 3, 4, 5] [2, -3, 4, -5] [2, 3, 4, 5] [2, 3, 4, 5]