From 011d5e8fd6eb233c3072c82ed7d48b6f6360e8c1 Mon Sep 17 00:00:00 2001 From: LJ <23249107+LJNeon@users.noreply.github.com> Date: Wed, 31 Jan 2024 17:43:04 -0700 Subject: [PATCH] BUGFIX: Properly deep copy array data for coding contracts (#1064) --- src/NetscriptFunctions/CodingContract.ts | 13 ++----------- src/data/codingcontracttypes.ts | 4 ++-- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/NetscriptFunctions/CodingContract.ts b/src/NetscriptFunctions/CodingContract.ts index 3a9790424..301340415 100644 --- a/src/NetscriptFunctions/CodingContract.ts +++ b/src/NetscriptFunctions/CodingContract.ts @@ -67,17 +67,8 @@ export function NetscriptCodingContract(): InternalAPI { const contract = getCodingContract(ctx, hostname, filename); const data = contract.getData(); if (Array.isArray(data)) { - // For two dimensional arrays, we have to copy the internal arrays using - // slice() as well. As of right now, no contract has arrays that have - // more than two dimensions - const copy = data.slice(); - for (let i = 0; i < copy.length; ++i) { - if (data[i].constructor === Array) { - copy[i] = data[i].slice(); - } - } - - return copy; + // For multi-dimensional arrays, we have to copy the internal arrays as well + return JSON.parse(JSON.stringify(data)); } else return data; }, getDescription: (ctx) => (_filename, _hostname?) => { diff --git a/src/data/codingcontracttypes.ts b/src/data/codingcontracttypes.ts index 5d5ae8f6b..31e9d8afa 100644 --- a/src/data/codingcontracttypes.ts +++ b/src/data/codingcontracttypes.ts @@ -1198,9 +1198,9 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [ `"1+01" is not a valid expression`, "Examples:\n\n", `Input: digits = "123", target = 6\n`, - `Output: [1+2+3, 1*2*3]\n\n`, + `Output: ["1+2+3", "1*2*3"]\n\n`, `Input: digits = "105", target = 5\n`, - `Output: [1*0+5, 10-5]`, + `Output: ["1*0+5", "10-5"]`, ].join(" "); }, difficulty: 10,