I wrote to the code to match the same places but there is a thing which I can not understand.
let myPlaces = [‘Istanbul’,‘Bursa’,‘Ankara’];
let friendPlaces = [‘istanbul’,‘Adana’,‘Denizli’];
for (let myPlacesIndex = 0; myPlacesIndex < myPlaces.length; myPlacesIndex++){
for (let friendPlacesIndex = 0; friendPlacesIndex < friendPlaces.length; friendPlacesIndex++){
if(myPlaces[myPlacesIndex]===friendPlaces[friendPlacesIndex]){
return console.log('Match: '+myPlaces[myPlacesIndex]);
}
}
}
When we write like above, there is no problem and the code works smoothly. Let’s add new same places but in a different position.
let myPlaces = [‘istanbul’,‘Bursa’,‘Ankara’,‘England’];
let friendPlaces = [‘istanbul’,‘England’,‘Adana’,‘Bursa’];
for (let myPlacesIndex = 0; myPlacesIndex < myPlaces.length; myPlacesIndex++){
for (let friendPlacesIndex = 0; friendPlacesIndex < friendPlaces.length; friendPlacesIndex++){
if(myPlaces[myPlacesIndex]===friendPlaces[friendPlacesIndex]){
return console.log('Match: '+myPlaces[myPlacesIndex]);
}
}
}
The output is the same again. The code writes only Istanbul. Why doesn’t write England too?
How can I fix this?