This commit is contained in:
Philippe Torrel
2026-09-28 09:42:41 +02:00
parent 8a2d979830
commit 80296c10d0
6 changed files with 89 additions and 16 deletions
+24 -2
View File
@@ -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>