Skip to content
Advertisement

Trying to find unique subarrays and sub-elements?

I have an array will subarrays containing [page_name, url, and id] in dirty_pages. This array contain duplicate subarrays.

I need to parse each subarray in dirty_pages into clean_pages such that:

  1. there are no duplicates (repeating subarray)

  2. the 1st index in the subarray i.e. the url must be unique! For example This url should be counted as one (url/#review is still the same url):

    JavaScript

    and

    JavaScript

My current attempt returns clean_pages with 6 subarrays (duplicates!) while the correct answer should be 4

JavaScript

UPDATE EXAMPLE – Apologies if example wasn’t clear (just like # after url these should be considered one url)

JavaScript

Advertisement

Answer

You can use furl for normalizing the urls

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement