Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.7 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6a0dcd03ee4e68698080ef66 Challenge 302: Jet Lagged 28 challenge-302

--description--

Given a departure city, an arrival city, a flight duration in hours, and a direction of travel, return the number of jet lag hours the traveller is experiencing.

The given cities will be from the following list that includes their UTC offset:

City Offset
"Los Angeles" -8
"New York" -5
"London" 0
"Istanbul" +3
"Dubai" +4
"Hong Kong" +8
"Tokyo" +9

To calculate jet lag hours:

  1. Find the timezone difference in hours between the two cities.
  2. Determine the direction multiplier. If travelling "east", it's 1.5, otherwise, it's 1.0.
  3. Get the jet lag hours with the formula: timezone difference + (flight duration * 0.1) * direction multiplier

Return the jet lag hours rounded to one decimal place.

--hints--

getJetLagHours("Istanbul", "Hong Kong", 10, "east") should return 6.5.

assert.equal(getJetLagHours("Istanbul", "Hong Kong", 10, "east"), 6.5);

getJetLagHours("London", "New York", 8, "west") should return 5.8.

assert.equal(getJetLagHours("London", "New York", 8, "west"), 5.8);

getJetLagHours("Hong Kong", "Tokyo", 4, "east") should return 1.6.

assert.equal(getJetLagHours("Hong Kong", "Tokyo", 4, "east"), 1.6);

getJetLagHours("Dubai", "London", 7, "west") should return 4.7.

assert.equal(getJetLagHours("Dubai", "London", 7, "west"), 4.7);

getJetLagHours("Los Angeles", "Hong Kong", 15, "west") should return 17.5.

assert.equal(getJetLagHours("Los Angeles", "Hong Kong", 15, "west"), 17.5);

getJetLagHours("Tokyo", "Dubai", 9, "west") should return 5.9.

assert.equal(getJetLagHours("Tokyo", "Dubai", 9, "west"), 5.9);

getJetLagHours("New York", "Istanbul", 10, "east") should return 9.5.

assert.equal(getJetLagHours("New York", "Istanbul", 10, "east"), 9.5);

--seed--

--seed-contents--

function getJetLagHours(departureCity, arrivalCity, flightDuration, direction) {

  return departureCity;
}

--solutions--

function getJetLagHours(departureCity, arrivalCity, flightDuration, direction) {
  const offsets = {
    "Los Angeles": -8,
    "New York": -5,
    "London": 0,
    "Istanbul": +3,
    "Dubai": +4,
    "Hong Kong": +8,
    "Tokyo": +9
  };

  const depOffset = offsets[departureCity];
  const arrOffset = offsets[arrivalCity];

  const timezoneDiff = Math.abs(arrOffset - depOffset);
  const multiplier = direction === "east" ? 1.5 : 1.0;

  const score = timezoneDiff + (flightDuration * 0.1) * multiplier;
  return Math.round(score * 10) / 10;
}