v. vanilla 2.0

examples/stdlib.v

← All source files · Download this file

1,553 bytes · SHA256 86588e605f67830f30d349702a8fd640a11642292994b2d326fe6eab7934a97d

function main
var prices sorted distinct part result items value defaults overrides merged
array create $prices 10 2.50 2.50 1
array sort $sorted $prices numeric
array unique $distinct $sorted
array slice $part $distinct 0 2
join $result $part ", "
echo "Lowest distinct prices: " $result "\n"
array reverse $part $part
array find $result $part 1
echo "Index of 1 after reverse: " $result "\n"
array remove $part $part 0
join $result $part ", "
echo "After removal: " $result "\n"
json parse $items "[]"
json parse $value 2.5
json append $items $value
json insert $items 0 label
json contains $result $items $value
echo "Contains numeric price: " $result "\n"
json remove $items 0
json length $result $items
echo "Item count: " $result "\n"
json parse $defaults "{\"currency\":\"USD\",\"places\":2}"
json parse $overrides "{\"places\":3}"
json merge $merged $defaults $overrides right
json stringify $result $merged
echo "Merged options: " $result "\n"
text startswith $result invoice-42 invoice-
echo "Invoice prefix: " $result "\n"
text endswith $result invoice-42 -42
echo "Invoice suffix: " $result "\n"
text contains $result invoice-42 voice
echo "Invoice contains: " $result "\n"
text padleft $result 42 5 0
echo "Padded identifier: " $result "\n"
text padright $result USD 5 .
echo "Padded currency: " $result "\n"
number valid $result 2.50
echo "Valid number: " $result "\n"
number convert $result +002.50
echo "Normalized number: " $result "\n"
number format $result 2.675 2
echo "Binary64 rounded (not exact decimal): " $result "\n"
kill main