d2718
1
I am attempting the Resistor Color Trio exercise in the Red track. In the test script, the first test says this:
16 │ expected: #(
17 │ value: 33
18 │ unit: "ohms"
19 │ )
and I can’t, for the life of me, figure out how it wants those values returned. My function correctly calculates 33 ohms, but I have tried returning
make object! [
value: 33
unit: "ohms"
]
and
make map! ["value" 33 "unit" "ohms"]
and even in desperation the string “33 ohms” (like the text of the exercise suggests), but none of these satisfy the test script.
Does anyone have any suggestions for how I should format my output?
This link looks relevant: docs/map.adoc at master · red/docs · GitHub
Looks like you don’t want to use a string for the key.
I think a common implementation is to return a string.
return sprintf("%d %s", value, unit);
But each track can interpret that data however they decide!
d2718
4
This did it! Thank you so much.
NB for future searchers: The elements of the list passed to make map!
aren’t evaluated, so ended up having to do this:
resistance: ...etc
m: make map! []
m/value: resistance
m/unit: "ohms"
The docs indicate to me that this might be valid:
make map! [value 33 unit "ohms"]
Exactly. You usually use reduce
or compose
for this:
>> resistance: 33
== 33
>> m: make map! compose [value (resistance) unit "ohms"]
== #[
value: 33
unit: "ohms"
]
>> m: make map! reduce ['value resistance 'unit "ohms"]
== #[
value: 33
unit: "ohms"
]