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

//@version=5

// @description Additional functions for array.
library(title="xarray", overlay=true)

// n_args = 1
// @function Remove duplicates in arrays.
// @param array_in (int[]/float[]/string[]) Array contains duplicates.
export remove_duplicates(int[] array_in_out) =>
    array_out = array_in_out
    int i = 0
    int j = na
    while i < array.size(array_out)
        while true
            j := array.lastindexof(array_out, array.get(array_out, i))
            if j > i
                array.remove(array_out, j)
            else 
                break
        i += 1

export remove_duplicates(float[] array_in_out) =>
    array_out = array_in_out
    int i = 0
    int j = na
    while i < array.size(array_out)
        while true
            j := array.lastindexof(array_out, array.get(array_out, i))
            if j > i
                array.remove(array_out, j)
            else 
                break
        i += 1

export remove_duplicates(string[] array_in_out) =>
    array_out = array_in_out
    int i = 0
    int j = na
    while i < array.size(array_out)
        while true
            j := array.lastindexof(array_out, array.get(array_out, i))
            if j > i
                array.remove(array_out, j)
            else 
                break
        i += 1

export remove_duplicates(bool[] array_in_out) =>
    array_out = array_in_out
    int i = 0
    int j = na
    while i < array.size(array_out)
        while true
            j := array.lastindexof(array_out, array.get(array_out, i))
            if j > i
                array.remove(array_out, j)
            else 
                break
        i += 1

// n_args = 2
// @param array_in_out_1 (int[]/float[]/string[]) Array contains duplicates.
// @param array_in_out_2 (int[]/float[]/string[]) Array contains duplicates.
export remove_duplicates(int[] array_in_out_1, float[] array_in_out_2) =>
    array_out_1 = array_in_out_1
    array_out_2 = array_in_out_2

    int i = 0
    while i < array.size(array_out_1)
        int j = i + 1
        while j < array.size(array_out_1)
            if array.get(array_out_1, j) == array.get(array_out_1, i) and array.get(array_out_2, j) == array.get(array_out_2, i)
                array.remove(array_out_1, j)
                array.remove(array_out_2, j)
            else
                j += 1
        i += 1

export remove_duplicates(float[] array_in_out_1, int[] array_in_out_2) =>
    array_out_1 = array_in_out_1
    array_out_2 = array_in_out_2

    int i = 0
    while i < array.size(array_out_1)
        int j = i + 1
        while j < array.size(array_out_1)
            if array.get(array_out_1, j) == array.get(array_out_1, i) and array.get(array_out_2, j) == array.get(array_out_2, i)
                array.remove(array_out_1, j)
                array.remove(array_out_2, j)
            else
                j += 1
        i += 1

//
export remove_duplicates(int[] array_in_out_1, string[] array_in_out_2) =>
    array_out_1 = array_in_out_1
    array_out_2 = array_in_out_2

    int i = 0
    while i < array.size(array_out_1)
        int j = i + 1
        while j < array.size(array_out_1)
            if array.get(array_out_1, j) == array.get(array_out_1, i) and array.get(array_out_2, j) == array.get(array_out_2, i)
                array.remove(array_out_1, j)
                array.remove(array_out_2, j)
            else
                j += 1
        i += 1

export remove_duplicates(string[] array_in_out_1, int[] array_in_out_2) =>
    array_out_1 = array_in_out_1
    array_out_2 = array_in_out_2

    int i = 0
    while i < array.size(array_out_1)
        int j = i + 1
        while j < array.size(array_out_1)
            if array.get(array_out_1, j) == array.get(array_out_1, i) and array.get(array_out_2, j) == array.get(array_out_2, i)
                array.remove(array_out_1, j)
                array.remove(array_out_2, j)
            else
                j += 1
        i += 1

//
export remove_duplicates(float[] array_in_out_1, string[] array_in_out_2) =>
    array_out_1 = array_in_out_1
    array_out_2 = array_in_out_2

    int i = 0
    while i < array.size(array_out_1)
        int j = i + 1
        while j < array.size(array_out_1)
            if array.get(array_out_1, j) == array.get(array_out_1, i) and array.get(array_out_2, j) == array.get(array_out_2, i)
                array.remove(array_out_1, j)
                array.remove(array_out_2, j)
            else
                j += 1
        i += 1

export remove_duplicates(string[] array_in_out_1, float[] array_in_out_2) =>
    array_out_1 = array_in_out_1
    array_out_2 = array_in_out_2

    int i = 0
    while i < array.size(array_out_1)
        int j = i + 1
        while j < array.size(array_out_1)
            if array.get(array_out_1, j) == array.get(array_out_1, i) and array.get(array_out_2, j) == array.get(array_out_2, i)
                array.remove(array_out_1, j)
                array.remove(array_out_2, j)
            else
                j += 1
        i += 1

//
export remove_duplicates(int[] array_in_out_1, int[] array_in_out_2) =>
    array_out_1 = array_in_out_1
    array_out_2 = array_in_out_2

    int i = 0
    while i < array.size(array_out_1)
        int j = i + 1
        while j < array.size(array_out_1)
            if array.get(array_out_1, j) == array.get(array_out_1, i) and array.get(array_out_2, j) == array.get(array_out_2, i)
                array.remove(array_out_1, j)
                array.remove(array_out_2, j)
            else
                j += 1
        i += 1

export remove_duplicates(float[] array_in_out_1, float[] array_in_out_2) =>
    array_out_1 = array_in_out_1
    array_out_2 = array_in_out_2

    int i = 0
    while i < array.size(array_out_1)
        int j = i + 1
        while j < array.size(array_out_1)
            if array.get(array_out_1, j) == array.get(array_out_1, i) and array.get(array_out_2, j) == array.get(array_out_2, i)
                array.remove(array_out_1, j)
                array.remove(array_out_2, j)
            else
                j += 1
        i += 1

export remove_duplicates(string[] array_in_out_1, string[] array_in_out_2) =>
    array_out_1 = array_in_out_1
    array_out_2 = array_in_out_2

    int i = 0
    while i < array.size(array_out_1)
        int j = i + 1
        while j < array.size(array_out_1)
            if array.get(array_out_1, j) == array.get(array_out_1, i) and array.get(array_out_2, j) == array.get(array_out_2, i)
                array.remove(array_out_1, j)
                array.remove(array_out_2, j)
            else
                j += 1
        i += 1

// n_args = 3
export remove_duplicates(int[] array_in_out_1, float[] array_in_out_2, bool[] array_in_out_3) =>
    array_out_1 = array_in_out_1
    array_out_2 = array_in_out_2
    array_out_3 = array_in_out_3

    int i = 0
    while i < array.size(array_out_1)
        int j = i + 1
        while j < array.size(array_out_1)
            if array.get(array_out_1, j) == array.get(array_out_1, i) and array.get(array_out_2, j) == array.get(array_out_2, i) and array.get(array_out_3, j) == array.get(array_out_3, i)
                array.remove(array_out_1, j)
                array.remove(array_out_2, j)
                array.remove(array_out_3, j)
            else
                j += 1
        i += 1

export remove_duplicates(float[] array_in_out_1, int[] array_in_out_2, bool[] array_in_out_3) =>
    array_out_1 = array_in_out_1
    array_out_2 = array_in_out_2
    array_out_3 = array_in_out_3

    int i = 0
    while i < array.size(array_out_1)
        int j = i + 1
        while j < array.size(array_out_1)
            if array.get(array_out_1, j) == array.get(array_out_1, i) and array.get(array_out_2, j) == array.get(array_out_2, i) and array.get(array_out_3, j) == array.get(array_out_3, i)
                array.remove(array_out_1, j)
                array.remove(array_out_2, j)
                array.remove(array_out_3, j)
            else
                j += 1
        i += 1

export remove_duplicates(int[] array_in_out_1, float[] array_in_out_2, string[] array_in_out_3) =>
    array_out_1 = array_in_out_1
    array_out_2 = array_in_out_2
    array_out_3 = array_in_out_3

    int i = 0
    while i < array.size(array_out_1)
        int j = i + 1
        while j < array.size(array_out_1)
            if array.get(array_out_1, j) == array.get(array_out_1, i) and array.get(array_out_2, j) == array.get(array_out_2, i) and array.get(array_out_3, j) == array.get(array_out_3, i)
                array.remove(array_out_1, j)
                array.remove(array_out_2, j)
                array.remove(array_out_3, j)
            else
                j += 1
        i += 1

export remove_duplicates(float[] array_in_out_1, int[] array_in_out_2, string[] array_in_out_3) =>
    array_out_1 = array_in_out_1
    array_out_2 = array_in_out_2
    array_out_3 = array_in_out_3

    int i = 0
    while i < array.size(array_out_1)
        int j = i + 1
        while j < array.size(array_out_1)
            if array.get(array_out_1, j) == array.get(array_out_1, i) and array.get(array_out_2, j) == array.get(array_out_2, i) and array.get(array_out_3, j) == array.get(array_out_3, i)
                array.remove(array_out_1, j)
                array.remove(array_out_2, j)
                array.remove(array_out_3, j)
            else
                j += 1
        i += 1
