Rate my Code for "Intermediate Algorithm: Sorted Union"

Hi together
I passed the Intermediate Algorithm Task “Sorted Union” with the code below.
Is this a good, intermediate or bad solution? Please rate my code and give me some feedback.
Thx.


function uniteUnique(arr) {
let result = [];
[...arguments].flat().forEach(el => { if (!(el in result)) result.push(el) });
return result;
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0.

Challenge: Sorted Union

Link to the challenge:

2 Likes

Hi @n8trufe,

I like the solution you provided. If I would try to solve this problem:

function uniteUnique() {
  return [...new Set([...arguments].flat())]
}
2 Likes

Hi @sherbakov1,
Thank you. Until now, I know nothing about the Set-Constructor. Just that this is relatively new to JS.

1 Like

No worries! Sometimes it can help you to solve problems like that. https://alligator.io/js/sets-introduction/

Nevertheless, you have a great solution! Good job!

Thank you very much. And btw I like your resource alligator.io a lot

1 Like