Crossing the Date Line — JavaScript Bug Hunt

Modelled on the F-22 Raptor date-line incident (February 2007): a flight of six aircraft crossed the 180th meridian on the way to Okinawa and every onboard…

  • Language: JavaScript
  • Layer: Backend
  • Difficulty: Medium
  • Concepts: Coordinates, Wraparound
  • Modelled on: F-22 Raptor · 2007
  • Visible tests: an ordinary eastward hop; crossing the antimeridian takes the short way
  • Reward: 50 XP for a complete fix

Briefing

Modelled on the F-22 Raptor date-line incident (February 2007): a flight of six aircraft crossed the 180th meridian on the way to Okinawa and every onboard computer crashed at once, losing navigation and fuel systems. The jets had to follow their tankers back by sight.

navigation.js computes the shortest longitude difference between two points and does not handle the wrap at ±180.

Fix longitudeDelta so it returns the shortest signed difference, always in the range (-180, 180].

Bug report

BUG-DATELINE · Priority: Critical · Reported by: flight test

longitudeDelta(from, to) returns the shortest signed difference in degrees:

  • positive when heading east, negative when heading west
  • always within (-180, 180]

Observed: crossing the antimeridian from 179 to -179 reports -358 instead of the correct +2, which sends the whole navigation solution off the map.

Logs

[nav] delta=-358.0 from=179.0 to=-179.0
[nav] course solution rejected; system reset

The code as shipped

src/nav/navigation.js (editable)

// Shortest signed longitude difference, in degrees.
exports.longitudeDelta = function (from, to) {
  return to - from;
};

Read-only context: src/nav/SPEC.js.

Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.