Most appropriate sub-area of p5.js?
Utilities
p5.js version
2.x main (4b096e2)
Actual vs expected behavior
shuffle() documents: "By default, the original array won't be modified. Instead, a copy will be created, shuffled, and returned." But the implementation treats every typed array as if modify were true:
const isView = ArrayBuffer && ArrayBuffer.isView && ArrayBuffer.isView(arr);
arr = modify || isView ? arr : arr.slice();
Executed repro:
const a = new Float32Array([1,2,3,4,5,6,7,8]);
const b = shuffle(a); // no modify flag
// a is now shuffled in place, and b === a
The isView special case predates TypedArray.prototype.slice (ES2015); every typed array has had .slice() for a decade, so the copy path works fine for them today.
Steps to reproduce
Run the snippet above in any 2.x sketch. Output from an executed run against main: original 1,2,3,4,5,6,7,8 became 1,8,3,7,4,6,2,5 and the return value is the same object.
Note
I have a fix ready (drop the isView special case) with two unit tests (typed array not modified by default, still modified in place with modify: true), mutation-tested against main. shuffle is not deprecated in 2.0. Filing for approval first per the contributing guide; will open the PR once approved.
Most appropriate sub-area of p5.js?
Utilities
p5.js version
2.x main (4b096e2)
Actual vs expected behavior
shuffle()documents: "By default, the original array won't be modified. Instead, a copy will be created, shuffled, and returned." But the implementation treats every typed array as ifmodifyweretrue:Executed repro:
The
isViewspecial case predatesTypedArray.prototype.slice(ES2015); every typed array has had.slice()for a decade, so the copy path works fine for them today.Steps to reproduce
Run the snippet above in any 2.x sketch. Output from an executed run against main: original
1,2,3,4,5,6,7,8became1,8,3,7,4,6,2,5and the return value is the same object.Note
I have a fix ready (drop the
isViewspecial case) with two unit tests (typed array not modified by default, still modified in place withmodify: true), mutation-tested against main.shuffleis not deprecated in 2.0. Filing for approval first per the contributing guide; will open the PR once approved.