Background: scraping school records via JSONP in the browser console. The lesson is not the site — it is that reduce is not always the right merge tool when your batches are not plain arrays.
After reading David Walsh on combining arrays and Chinese translations, I tried:
1 | // g, b are arrays |
With larger batches this became very slow. The payload looked like:
Object { 1=[8], 2=[8], 3=[8], ... }
That is a map-like object, not a dense array. reduce walks array indices; pushing into a growing accumulator on huge lists is costly compared with a single concat.
Why concat worked — from MDN Array.prototype.concat:
- Builds a new array from the receiver plus arguments.
- For objects/arrays, stores references (shallow copy).
- For primitives, copies values.
Know your shape: array batches → concat / spread; object maps → Object.values then merge, or push into a real array first.
2D de-duplication sketch (PHP):
1 | function array_unique_deep($array2D) { |
Read N CSV lines (PHP):
1 | function csv_get_lines($csvfile, $lines, $offset = 0) { |
Questions? Leave a comment below or email: newbvirgil@gmail.com![]()
