Both of these solutions are exponentially slow due to the need to search the growing unique array (includes and indexOf do a linear search). You can do the unique array in O(N) using a Set, Map or in this case a PoJo. The one liner using Set is:
Tech Lead/Team Lead. Senior WebDev.
Intermediate Grade on Computer Systems-
High Grade on Web Application Development-
MBA (+Marketing+HHRR).
Studied a bit of law, economics and design
Location
Spain
Education
Higher Level Education Certificate on Web Application Development
To add context here for learning purposes, a POJO is an object that only contains data (as opposed to methods or internal state), most JavaScript codebases consider objects created using curly braces {} to be POJOs, however, more strict codebases sometimes create POJOs by calling Object.create(null) to avoid inheriting from the built-in Object class.
JavaScript Maps are an alternative to POJOs for storing data because they neither inherit keys from the Object class.
A downside is that objects are generally easier to work with than maps cause not all JS functions, frameworks, and libs support maps.
i.e. JSON.stringify() function doesn't serialize maps by default:
Both of these solutions are exponentially slow due to the need to search the growing unique array (
includesandindexOfdo a linear search). You can do the unique array in O(N) using a Set, Map or in this case a PoJo. The one liner using Set is:Best friends are options kk thanks
To add context here for learning purposes, a POJO is an object that only contains data (as opposed to methods or internal state), most JavaScript codebases consider objects created using curly braces
{}to be POJOs, however, more strict codebases sometimes create POJOs by callingObject.create(null)to avoid inheriting from the built-inObjectclass.JavaScript
Maps are an alternative to POJOs for storing data because they neither inherit keys from theObjectclass.A downside is that objects are generally easier to work with than maps cause not all JS functions, frameworks, and libs support maps.
i.e.
JSON.stringify()function doesn't serialize maps by default: