18 Sep 2023

Write a Function that Returns Unique Values from Arrays in the order of Insertion

Taken from FreeCodeCamp

Write a function that takes two or more arrays and returns a new array of unique values in the order of the original provided arrays.

In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array.

The unique numbers should be sorted by their original order, but the final array should not be sorted in numerical order.


This is the answer I came up with:

function uniteUnique(...arr: any): any {
    let workingArr = arr.flat(Infinity)

    let unique = new Set(workingArr)

    return Array.from(unique)


Solution tested in REPL:


Copyright © Paramdeo Singh · All Rights Reserved · Built with Jekyll

This node last updated November 7, 2023 and is permanently morphing...

Paramdeo Singh Guyana

Generalist. Edgerunner. Riding the wave of consciousness in this treacherous mortal sea.

Technology Design Strategy Literature Personal Blogs
Search Site

Results are from Blog, Link Dumps, and #99Problems