I am getting a response which returns and an array of hashes. The array of hashes has two keys "title", and "paragraph". Sometimes I get responses that return similar values within the paragraph key.
For example when I just return the values in the paragraph:
["Welcome to the best place", "Welcome to the best place in the world, Boston!"]
You see that at index 0 it includes what is at index 1
I am mapping through the array of hashes to return one of the keys, "paragraph". I then try to filter out the first element if the value is equal to any of the other elements in the array. I have something that only works when the array has similar values as state above and will return an empty array if it fails.
const description = hotel
.description()
.map(descriptions => descriptions.paragraph)
.filter((paragraph, index) => !paragraph[index].includes(paragraph[0]))
Where hotel.description()
returns the array of hashes and the map chain to filter will return the results in an array
The example code above returns a valid response where array:
["Welcome to the best place", "Welcome to the best place in the world, Boston!"]
Becomes:
["Welcome to the best place in the world, Boston!"]
But if the array return is unique an empty array is returned.
The expected results are:
["You are here at the best place", "Welcome to the best place in the world, Boston!"]
The actual results are:
[]
Not sure what else to append to this chain to get it to return the unique values.