First-class functions/Use numbers analogously: Difference between revisions
Content added Content deleted
(Added Wren) |
|||
Line 779: | Line 779: | ||
As of this writing, there is no entry for jq at [[First-class functions]]. |
As of this writing, there is no entry for jq at [[First-class functions]]. |
||
=={{header|JavaScript}}== |
|||
<lang javascript>const x = 2.0; |
|||
const xi = 0.5; |
|||
const y = 4.0; |
|||
const yi = 0.25; |
|||
const z = x + y; |
|||
const zi = 1.0 / (x + y); |
|||
const pairs = [[x, xi], [y, yi], [z, zi]]; |
|||
const testVal = 0.5; |
|||
const multiplier = (a, b) => m => a * b * m; |
|||
const test = () => { |
|||
return pairs.map(([a, b]) => { |
|||
const f = multiplier(a, b); |
|||
const result = f(testVal); |
|||
return `${a} * ${b} * ${testVal} = ${result}`; |
|||
}); |
|||
} |
|||
test().join('\n');</lang> |
|||
{{out}} |
|||
<pre> |
|||
2 * 0.5 * 0.5 = 0.5 |
|||
4 * 0.25 * 0.5 = 0.5 |
|||
6 * 0.16666666666666666 * 0.5 = 0.5 |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |