9.1.18--Use reduce to concatenate all the countries and to produce this sentence: Estonia, Finland, Sweden, Denmark, Norway, and IceLand are north European countries #113
const countriesReduce=countries.reduce(concate)
function concate(result,current){
return result+current;
}
console.log(countriesReduce);``
//9.1.18--Use reduce to concatenate all the countries and to produce this sentence:
//Estonia, Finland, Sweden, Denmark, Norway, and IceLand are north European countries
//const countriesReduce=countries.reduce((accu,curr)=>console.log(accu,curr))
const countriesReduce=countries.reduce(concate)
function concate(result,current,i){ //result points 1st element,current points next/2nd element,i is index of current
console.log(result)
console.log(i)
console.log(current)
if(i==4){
return result+" and "+current+" are north European countries "
}
else{
return result+","+current;
}
}
console.log(countriesReduce);
const countriesReduce=countries.reduce(concate)
function concate(result,current,i){ //result points 1st element,current points next/2nd element,i is index of current
//console.log(result)
// console.log(i)
//console.log(current)
if(i==4){
return result+" and "+current+" are north European countries "
}
else{
return result+","+current;
}
}
console.log(countriesReduce);