RosettaCodeData/Task/Remove-duplicate-elements/Neko/remove-duplicate-elements.neko

25 lines
545 B
Plaintext

/**
Remove duplicate elements, in Neko
*/
var original = $array(1, 2, 1, 4, 5, 2, 15, 1, 3, 4)
/* Create a table with only unique elements from the array */
var dedup = function(a) {
var size = $asize(a)
var hash = $hnew(size)
while size > 0 {
var v = a[size - 1]
var k = $hkey(v)
$hset(hash, k, v, null)
size -= 1
}
return hash
}
/* Show the original list and the unique values */
$print(original, "\n")
var show = function(k, v) $print(v, " ")
$hiter(dedup(original), show)
$print("\n")