const assert = require('assert');
const foo = Buffer.from([0, 1, 2, 3]);
const bar = Buffer.from([1, 2, 3, 4]);
const LESS_THAN = -1;
const EQUAL = 0;
assert.equal(foo.compare(bar), LESS_THAN, 'Without indices, foo is less.');
assert.equal(foo.compare(bar, 0, 3, 1, 4), EQUAL, 'With indices which compare only the 1..3 from each buffer, foo and bar are equal.');
assert.equal(foo.compare(bar, undefined, 3, 1, 4), LESS_THAN, 'With targetStart undefined, all other indices should be ignored.');
Although both behaviors (ignoring or not ignoring subsequent parameters) seem reasonable, it looks like the discrepancy has always existed (see 473f086, which introduced the feature), so it probably makes more sense to change the docs.
In the documentation for Buffer#compare, it's stated that the
targetEnd,sourceStart, andsourceEndparameters are each "ignored whentargetStartisundefined". However, I do not observe that behavior on versions 6.12.2, 8.9.3, or 9.2.1. Instead, the following code fails the third assertion:Although both behaviors (ignoring or not ignoring subsequent parameters) seem reasonable, it looks like the discrepancy has always existed (see 473f086, which introduced the feature), so it probably makes more sense to change the docs.