Skip to content

Instantly share code, notes, and snippets.

@daviddamilola
Last active April 12, 2021 09:01
Show Gist options
  • Save daviddamilola/5e99da275d34291648c32e204c2a95ce to your computer and use it in GitHub Desktop.
Save daviddamilola/5e99da275d34291648c32e204c2a95ce to your computer and use it in GitHub Desktop.
remove duplicates
export const getUniqueItemsFromArray = (array=[]) => {
return Array.from(new Set(array)).length()
}
@mejtfk
Copy link

mejtfk commented Apr 12, 2021

Woah, very efficient. Good!

@meekg33k
Copy link

meekg33k commented Apr 12, 2021

If you can solve a problem in fewer lines of code, do it and you definitely did that @daviddamilola. Thanks for participating in Week 1 of Algorithm Fridays.

I really like that your solution takes care of possible null values for input by setting a default value of the array to be an empty array.

The only question I have is, is there a way we could have solved this problem without using another data structure?

I have posted my solution here, let me know what you think.

@daviddamilola
Copy link
Author

many thanks for taking the time to give feedback @meekg33k , the counting solution is an eye opener for me and thinking of pros and cons to any approach too.... looking forward to next Friday🎉

@daviddamilola
Copy link
Author

Woah, very efficient. Good!

thanks @mejtfk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment