Skip to content

Instantly share code, notes, and snippets.

@jfacoustic
Created June 16, 2020 17:06
Show Gist options
  • Save jfacoustic/97e7fbf92ed32aecbb42fa7ce7d0dc1c to your computer and use it in GitHub Desktop.
Save jfacoustic/97e7fbf92ed32aecbb42fa7ce7d0dc1c to your computer and use it in GitHub Desktop.
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