#!/usr/bin/ruby

#
## Removes duplicated items from array
#


var array = [['a','b'], ['a'], ['a', 'b'], ['z']];

assert_eq(array.uniq, [["a", "b"], ["a"], ["z"]]);
assert_eq(array.last_uniq, [["a"], ["a", "b"], ["z"]]);

var a1 = @('a'..'z').shuffle;
var a2 = @('a'..'z').shuffle;

var nums = (a1 + a2);
assert_eq(nums.uniq, a1);
assert_eq(nums.last_uniq, a2);

assert_eq(nums.uniq_by { _ }, a1);
assert_eq(nums.last_uniq_by { _ }, a2);

## This is experimental
#var ary = [1,1,2,1,'redundant',[1,2,3],[1,2,3],'redundant'];
#assert_eq(ary.uniq, [1, 2, "redundant", [1, 2, 3]]);
#assert_eq(ary.last_uniq, [2, 1, [1, 2, 3], "redundant"]);

#
## Same thing, made simple
#

assert_eq([1,2,1,3,2].unique, [1,2,3]);

say "** Test passed!";
