fix(List): toString is different from toJSON

This commit is contained in:
2025-06-09 16:06:43 +03:00
parent d6ea567e73
commit 87a37b96b6
2 changed files with 7 additions and 2 deletions

View File

@ -120,13 +120,17 @@ export class SequenceContainer {
} }
toJSON() { toJSON() {
return this.toString() let res = []
for (const value of this) {
res.push(JSON.stringify(value))
}
return '[ ' + res.join(', ') + ' ]'
} }
toString() { toString() {
let res = [] let res = []
for (const value of this) { for (const value of this) {
res.push(JSON.stringify(value)) res.push(value.toString())
} }
return '[ ' + res.join(', ') + ' ]' return '[ ' + res.join(', ') + ' ]'
} }

View File

@ -134,4 +134,5 @@ test('pushBack, pushFront, popBack, popFront, back, front', () => {
test('toJSON, toString', () => { test('toJSON, toString', () => {
expect(List.from([1, 2]).toJSON()).toEqual('[ 1, 2 ]') expect(List.from([1, 2]).toJSON()).toEqual('[ 1, 2 ]')
expect(List.from([0n]).toString()).toEqual('[ 0 ]')
}) })