This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
@@ -35,7 +35,29 @@
|
||||
['Russia', 'Moscow'],
|
||||
];
|
||||
|
||||
const getCountryForCapital = () => {};
|
||||
const getCountryForCapital = (capital) => {
|
||||
for (const [country, countryCapital] of countriesWithCapital) {
|
||||
if (countryCapital === capital) {
|
||||
return country;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const getCountryForCapital2 = (capital) => {
|
||||
const foundCountryAr = countriesWithCapital.find(
|
||||
(arr) => arr[1].trim().toLowerCase() === capital.trim().toLowerCase(),
|
||||
);
|
||||
|
||||
return foundCountryAr ? foundCountryAr[0] : undefined;
|
||||
};
|
||||
|
||||
console.log('London:', getCountryForCapital2('London')); // => London: UK
|
||||
console.log('London:', getCountryForCapital2('london')); // => London: UK
|
||||
console.log('London:', getCountryForCapital2('')); // => London: undefined
|
||||
console.log('Paris:', getCountryForCapital2('Paris')); // => Paris: France
|
||||
console.log('Vienna:', getCountryForCapital2('Vienna')); // => Vienna: Austria
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user