From 847adaea725ea08fa5233d05a5b9d2ad17da333d Mon Sep 17 00:00:00 2001 From: koronya Date: Mon, 29 Dec 2025 21:39:29 +0900 Subject: [PATCH] [JS][7kyu] Lost Lineup --- codewars/7kyu/lost-lineup/koronya.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 codewars/7kyu/lost-lineup/koronya.js diff --git a/codewars/7kyu/lost-lineup/koronya.js b/codewars/7kyu/lost-lineup/koronya.js new file mode 100644 index 000000000..038864308 --- /dev/null +++ b/codewars/7kyu/lost-lineup/koronya.js @@ -0,0 +1,22 @@ +// [JS][7kyu] Lost Lineup +// lost-lineup +// https://www.codewars.com/kata/6914c975e159c8f7e120cc84/train/javascript + +const findLineup = (distances) => { + const distancesLength = distances.length + if (distances.some((distance) => distance < 0 || distance >= distancesLength) || new Set(distances).size !== distancesLength) { + return [] + } + return distances + .map((distance, index) => ({ distance, index: index + 1 })) + .sort((a, b) => a.distance - b.distance) + .map((item) => item.index) +} + +findLineup([1, 2, 0]) +findLineup([1, 4, 2, 6, 8, 0, 5, 7, 3]) +findLineup([0]) + +findLineup([1]) +findLineup([1, 0, 1]) +findLineup([1, 2, 0, 4])