From 3d99a61ca38a73461f59f927e567bbe3d81a9b93 Mon Sep 17 00:00:00 2001 From: David Ashby Date: Sun, 15 Dec 2024 22:38:00 -0500 Subject: [PATCH] some slight cleanup --- 09/index.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/09/index.ts b/09/index.ts index 146dcee..4c272cc 100644 --- a/09/index.ts +++ b/09/index.ts @@ -102,6 +102,7 @@ while (rightCursor > 0) { ); if (target.index < Infinity && target.index < rightCursor) { // slot exists; move the file, update the array, and update the space lists + // but only if the new location is actually to the right of our cursor sparceArray.splice( target.index, fileSize, @@ -114,11 +115,9 @@ while (rightCursor > 0) { ); spaces[target.size].shift(); if (toNum(target.size) - fileSize > 0) { - spaces[(toNum(target.size) - fileSize).toString()].unshift( - target.index + fileSize - ); - spaces[(toNum(target.size) - fileSize).toString()].sort((a, b) => - a > b ? 1 : -1 + let newGap = (toNum(target.size) - fileSize).toString(); + spaces[newGap] = [...spaces[newGap], target.index + fileSize].sort( + (a, b) => (a > b ? 1 : -1) ); } }