Sparkline in unicode: Difference between revisions

m (Removed incorrect example message. C++ version compile correctly under Linux (g++ 5.4.0))
Line 994:
 
=={{header|Julia}}==
<lang{{works with|Julia>|0.6}}
function sparklineit(a)
const sparkchars = '\u2581':'\u2588'
const dyn = length(sparkchars)
(lo, hi) = extrema(a)
b = max(iceil(dyn*(a-lo)/(hi-lo)), 1)
return join(sparkchars[b], "")
end
 
<lang julia>function sparklineit(arr::Vector{<:Integer})
function getnumbers(s)
asparkchars = split(s, r"[,,'\u2581':'\s]+")u2588'
adyn = trylength(sparkchars)
lo, hi = mapextrema(parseint, aarr::Vector{<:Integer})
b = @. max(iceilceil(Int, dyn * (aarr::Vector{<:Integer} - lo) / (hi - lo)), 1)
catch
return mapjoin(parsefloat, asparkchars[b])
end
end
 
v = rand(0:10, 10)
test = getnumbers("1 2 3 4 5 6 7 8 7 6 5 4 3 2 1")
println(test, "$v => ", sparklineit(testv))
v = 10rand(10)
 
println(test"$(round.(v, "2)) => ", sparklineit(testv))</lang>
test = getnumbers("1.5, 0.5 3.5, 2.5 5.5, 4.5 7.5, 6.5")
println(test, " => ", sparklineit(test))
</lang>
 
{{out}}
<pre>[6, 3, 9, 5, 1, 10, 0, 1, 3, 6] → ▅▃█▄▁█▁▁▃▅
<pre>
[0.57, 0.14, 4.73, 6.61, 6.9, 0.8, 9.71, 7.39, 2.75, 5.7] → ▁▁▄▆▆▁█▇▃▅</pre>
[1,2,3,4,5,6,7,8,7,6,5,4,3,2,1] => ▁▂▃▄▅▆▇█▇▆▅▄▃▂▁
[1.5,0.5,3.5,2.5,5.5,4.5,7.5,6.5] => ▂▁▄▃▆▅█▇
</pre>
 
=={{header|Kotlin}}==
Anonymous user