I have a list of cities and I have a list of phrases. I need to check if the cities exist in the phrases and based on this return "big city" or "not a big city"
I thought it would be simple with the some() function but I seem to be not clear about how it really works. I've tried with with a single string for a city and an array of cities.. but both don't seem to work..
I have check this question (Checking if elements of an array are included in elements of another array) and maybe the answer is there but there seems to be a use of filter there.. do I have to do that or can I not just use some and get the result?
I'd appreciate some help with some explanation why the below code does not work.. I've lost one day trying to figure it out but I can't seem to.. In my head the result
should be 'big city' twice in the code below .. once for 'new york' and once for 'milan'
// COMMON FOR BOTH
const phrases = ['I live in San Francisco','I live in milan in italy', 'I live in Los Angeles', 'I live in New York City']
// WITH AN ARRAY
const cities=['paris',"new york",'milan'];
function checkCities(phrase){
cities.forEach(city=> phrase.includes(city));
};
const result1 = phrases.some(checkCities) ? "big city" : "not a big city";
console.log('result1',result1); // Output "not a big city"
// WITH JUST A STRING
const city = 'new york';
const result2 = phrases.some(checkCity) ? "big city" : "not a big city";
console.log('result2',result2); // Output "not a big city
function checkCity(phrase){
phrase.includes(city);
};