RosettaCodeData/Task/Apply-a-callback-to-an-array/Jq/apply-a-callback-to-an-array-1.jq
2023-07-01 13:44:08 -04:00

14 lines
472 B
Text

# Illustration of map/1 using the builtin filter: exp
map(exp) # exponentiate each item in the input list
# A compound expression can be specified as the argument to map, e.g.
map( (. * .) + sqrt ) # x*x + sqrt(x)
# The compound expression can also be a composition of filters, e.g.
map( sqrt|floor ) # the floor of the sqrt
# Array comprehension
reduce .[] as $n ([]; . + [ exp ])
# Elementwise operation
[.[] + 1 ] # add 1 to each element of the input array