Price fraction: Difference between revisions
Content added Content deleted
(Tweak) |
(jq) |
||
Line 1,351: | Line 1,351: | ||
return values[(v * 100 - 1) / 5 | 0]; |
return values[(v * 100 - 1) / 5 | 0]; |
||
}</lang> |
}</lang> |
||
=={{header|jq}}== |
|||
The solution given here is based on the JavaScript solution. |
|||
<lang jq>def getScaleFactor: |
|||
["0.10","0.18","0.26","0.32","0.38","0.44","0.50","0.54", |
|||
"0.58","0.62","0.66","0.70","0.74","0.78","0.82","0.86", |
|||
"0.90","0.94","0.98","1.00"] as $values |
|||
| $values[ (. * 100 - 1) / 5 | floor ] ;</lang> |
|||
The full coverage test as given in the Ada example: |
|||
<lang jq>def test: |
|||
(range(0;10) | "0.0\(.) -> \( 0.01 * . | getScaleFactor)"), |
|||
(range(10;100) | "0.\(.) -> \( 0.01 * . | getScaleFactor)"); |
|||
test</lang>Run the test, showing the first few lines of output: |
|||
<lang sh> |
|||
$ jq -n -r -f Price_fraction.jq |
|||
0.00 -> 1.00 |
|||
0.01 -> 0.10 |
|||
0.02 -> 0.10 |
|||
0.03 -> 0.10 |
|||
0.04 -> 0.10 |
|||
0.05 -> 0.10 |
|||
0.06 -> 0.18 |
|||
0.07 -> 0.18 |
|||
0.08 -> 0.18 |
|||
0.09 -> 0.18 |
|||
0.10 -> 0.18 |
|||
0.11 -> 0.26 |
|||
...</lang> |
|||
=={{header|K}}== |
=={{header|K}}== |