RosettaCodeData/Task/First-class-functions-Use-numbers-analogously/Jq/first-class-functions-use-numbers-analogously.jq
2017-09-25 22:28:19 +02:00

21 lines
388 B
Text

# Infrastructure:
# zip this and that
def zip(that):
. as $this | reduce range(0;length) as $i ([]; . + [ [$this[$i], that[$i]] ]);
# The task:
def x: 2.0;
def xi: 0.5;
def y: 4.0;
def yi: 0.25;
def z: x + y;
def zi: 1.0 / (x + y);
def numlist: [x,y,z];
def invlist: [xi, yi, zi];
# Input: [x,y]
def multiplier(j): .[0] * .[1] * j;
numlist|zip(invlist) | map( multiplier(0.5) )