Light Mode
Dark Mode
Why AssertionError: [1,3,1,3] === [1,3,1,3] ?

I tried 'Non-unique Elements'. I do not under stand [AssertionError: [1,3,1,3] === [1,3,1,3]].

Please tell me why test fail?

import assert from "assert";

function nonUniqueElements(data: number[]): number[] {
    const dup = data.filter((val, i, data) => {
      return !(data.indexOf(val) === i);
    });
    return data.filter(val => (dup.indexOf(val) != -1));
}

console.log("Example:");
console.log(nonUniqueElements([1, 2, 3, 1, 3]));

// These "asserts" are used for self-checking
assert.strictEqual(nonUniqueElements([1, 2, 3, 1, 3]), [1, 3, 1, 3]);

result:
Example:
1,3,1,3
    AssertionError: [1,3,1,3] === [1,3,1,3]
eval Line: 14 Pos: 7
Created: Sept. 27, 2022, 12:13 a.m.
Updated: Sept. 27, 2022, 12:13 a.m.
0
7
User avatar
inzauma1114z_64cf7272736c4294a