FunctionArrayUnique
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RicardoSantos

//@version=5

// @description Method for retrieving the unique elements in a array.
//  for example [1, 2, 1, 1, 2] would retrieve a array with [1, 2],
//  the elements retrieved will be sorted by its first seen index in 
//  parent array.
//  note: float values have no precision option.
library("FunctionArrayUnique")


// Helper method for the unique() function
_unique (a) => //{
    int _size = array.size(a)
    if _size > 0
        _dict = array.from(array.get(a, 0)) // type detection
        for _i = 1 to _size-1
            _value = array.get(a, _i)
            if array.indexof(_dict, _value) < 0
                array.push(_dict, _value)
        _dict
    else
        runtime.error('array must have atleast one element.')
        array.copy(a)
//}

// @function method for retrieving the unique elements in a array.
// @param source array<float> source array to extract elements.
// @returns array<float> unique elements in the source array.
export unique (array<float>  source) => _unique(source)

// @function method for retrieving the unique elements in a array.
// @param source array<int> source array to extract elements.
// @returns array<int> unique elements in the source array.
export unique (array<int>    source) => _unique(source)

// @function method for retrieving the unique elements in a array.
// @param source array<string> source array to extract elements.
// @returns array<string> unique elements in the source array.
export unique (array<string> source) => _unique(source)

import RicardoSantos/DebugConsole/8 as console
a0 = array.from(1,2,3,1,3,5,4,1,2,4,-1,-0,1,-6,99999)
a1 = array.from('a', 'b', 'a', 'c', 'b')
b0 = str.tostring(unique(a0))
b1 = str.tostring(unique(a1))
console.log(bar_index%2==0?b0:b1)