gvwilson / sdxjs

Software Design by Example with JavaScript
Other
49 stars 12 forks source link

Fix array index so the example makes sense #27

Closed juananpe closed 1 year ago

juananpe commented 1 year ago

For this example:

const hosts = links.map(a => a.href.split(':')[1].split('/')[0]).unique()

I think that the number to index the array generated by the second split should be 2 instead of 0.

A small proof of my point follows. Here, using index 0 after the split, will yield an empty result:

let links = ['https://ikasten.io/cc/c.html', 'https://ehu.eus/bb/b.html', 'https://ikasten.io/aa/as.html']
const hosts = links.map(a=> console.log( a.split(':')[1].split('/')[0] ) )

While using 2 will yield the hostnames (on which we could apply the unique() function)

let links = ['https://ikasten.io/cc/c.html', 'https://ehu.eus/bb/b.html', 'https://ikasten.io/aa/as.html']
const hosts = links.map(a=> console.log( a.split(':')[1].split('/')[2] ) )
ikasten.io
ehu.eus
ikasten.io