Created
June 16, 2020 17:06
-
-
Save jfacoustic/97e7fbf92ed32aecbb42fa7ce7d0dc1c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cities = ['Tokyo', 'London', 'Rome', 'Donlon', 'Kyoto', 'Paris'].map(city => city.toLowerCase()); | |
const matches = cities.reduce((acc, curr) => { | |
const double = curr + curr; | |
const match = []; | |
cities.forEach(city => { | |
if(double.includes(city)) { | |
match.push(city); | |
} | |
}); | |
acc.push(JSON.stringify(match.sort())); | |
return acc; | |
}, []) | |
const matchesSet = new Set(matches); | |
const result = Array.from(matchesSet).map(pair => JSON.parse(pair)); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment