BUGFIX: Properly deep copy array data for coding contracts (#1064)

This commit is contained in:
LJ 2024-01-31 17:43:04 -07:00 committed by GitHub
parent 5277db2c65
commit 011d5e8fd6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 13 deletions

@ -67,17 +67,8 @@ export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
const contract = getCodingContract(ctx, hostname, filename); const contract = getCodingContract(ctx, hostname, filename);
const data = contract.getData(); const data = contract.getData();
if (Array.isArray(data)) { if (Array.isArray(data)) {
// For two dimensional arrays, we have to copy the internal arrays using // For multi-dimensional arrays, we have to copy the internal arrays as well
// slice() as well. As of right now, no contract has arrays that have return JSON.parse(JSON.stringify(data));
// 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;
} else return data; } else return data;
}, },
getDescription: (ctx) => (_filename, _hostname?) => { getDescription: (ctx) => (_filename, _hostname?) => {

@ -1198,9 +1198,9 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
`"1+01" is not a valid expression`, `"1+01" is not a valid expression`,
"Examples:\n\n", "Examples:\n\n",
`Input: digits = "123", target = 6\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`, `Input: digits = "105", target = 5\n`,
`Output: [1*0+5, 10-5]`, `Output: ["1*0+5", "10-5"]`,
].join(" "); ].join(" ");
}, },
difficulty: 10, difficulty: 10,