Comma quibbling: Difference between revisions

Content deleted Content added
Dinosaur (talk | contribs)
Fixed to most recent version
Line 1,870: Line 1,870:


=={{header|Julia}}==
=={{header|Julia}}==
{{works with|Julia|0.6}}
<lang Julia>quibble(words) =
<lang Julia>function quibble(arr::Array)
"{"* (isempty(words) ? "" :
if isempty(arr) rst = "" else rst = "$(arr[end])" end
length(words)==1? words[1] :
join(words[1:end-1],", ")*" and "*words[end]) *"}"</lang>
if length(arr) > 1 rst = join(arr[1:end-1], ", ") * " and " * rst end
return "{" * rst * "}"
{{Out}}
end
<pre>julia> quibble([])
"{}"


julia> quibble(["ABC"])
@show quibble([])
"{ABC}"
@show quibble(["ABC"])
@show quibble(["ABC", "DEF"])
@show quibble(["ABC", "DEF", "G", "H"])</lang>


{{Out}}
julia> quibble(["ABC","DEF"])
<pre>quibble([]) = "{}"
"{ABC and DEF}"
quibble(["ABC"]) = "{ABC}"

julia> quibble(["ABC","DEF","G","H"])
quibble(["ABC", "DEF"]) = "{ABC and DEF}"
"{ABC, DEF, G and H}"</pre>
quibble(["ABC", "DEF", "G", "H"]) = "{ABC, DEF, G and H}"</pre>


=={{header|Kotlin}}==
=={{header|Kotlin}}==