Skip to content

Commit 37e0909

Browse files
committed
complete data structure, modern operators and strings section
1 parent 7f909b1 commit 37e0909

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

09-Data-Structure-Modern-Operators-and-Strings/challenge.js

+25
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,28 @@ btn.addEventListener("click", function convertCase() {
341341
console.log(`${result.padEnd(20)} ${"✅".repeat(i + 1)}`);
342342
}
343343
});
344+
345+
// ----------------------------------------
346+
// String Methods Exerceise
347+
// ----------------------------------------
348+
349+
const flights =
350+
"_Delayed_Departure;fao93766109;txl2133758440;11:25+_Arrival;bru0943384722;fao93766109;11:45+_Delayed_Arrival;hel7439299980;fao93766109;12:05+_Departure;fao93766109;lis2323639855;12:30";
351+
352+
// 🔴 Delayed Departure from FAO to TXL (11h25)
353+
// Arrival from BRU to FAO (11h45)
354+
// 🔴 Delayed Arrival from HEL to FAO (12h05)
355+
// Departure from FAO to LIS (12h30)
356+
357+
const getCode = (str) => str.slice(0, 3).toUpperCase();
358+
359+
for (const flight of flights.split("+")) {
360+
const [type, from, to, time] = flight.split(";");
361+
const output = `${type.startsWith("_Delayed") ? "🔴" : ""} ${type
362+
.replaceAll("_", " ")
363+
.trim()} from ${getCode(from)} to ${getCode(to)} (${time.replace(
364+
":",
365+
"h"
366+
)})`.padStart(50);
367+
console.log(output);
368+
}

0 commit comments

Comments
 (0)