Skip to content

Strange behavior after clone #21

@AlexMost

Description

@AlexMost
const Heap = require('heap');

function msgidComparator(e1, e2) {
    if (e1.msgid > e2.msgid) {
        return 1;
    }
    if (e2.msgid > e1.msgid) {
        return -1;
    }
    return 0;
}

const data = [
    { msgid: 'aaaaa', msgstr: '' },
    { msgid: 'ccccc', msgstr: '' },
    { msgid: 'eeeee', msgstr: '' },
    { msgid: 'bbbb', msgstr: '' },
    { msgid: 'fffff', msgstr: '' }
]

const h = new Heap(msgidComparator);
h.push(data[0]);
h.push(data[1]);
h.push(data[2]);
h.push(data[3]);
h.push(data[4]);

const h1 = h.copy();

console.log(h1.pop());
console.log(h1.pop());
console.log(h1.pop());
console.log(h1.pop());
console.log(h1.pop());

Expected to see:

{ msgid: 'aaaaa', msgstr: '' }
{ msgid: 'bbbb', msgstr: '' }
{ msgid: 'ccccc', msgstr: '' }
{ msgid: 'eeeee', msgstr: '' }
{ msgid: 'fffff', msgstr: '' }

but have instead

{ msgid: 'aaaaa', msgstr: '' }
{ msgid: 'eeeee', msgstr: '' }
{ msgid: 'fffff', msgstr: '' }
{ msgid: 'bbbb', msgstr: '' }
{ msgid: 'ccccc', msgstr: '' }

Original object behaves well, the order is correct but clone seems to be broken.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions