Array pre-populate (fast)

by Ricardo “Rudxain” Fernández Serrata

Version 1 (December 1, 2023)

Download (20 downloads)

Creates and fills an array, without loops ("SIMD-like"). Based on the same hack as "String repeat": llamalab.com/automate/community/flows/43942 . Here the only performance penalty is `jsonDecode`.

The subroutine is intended to be embedded in flows. But before you do that, remember that `fill` must be JSON. You can pass `fill` as JSON to the subroutine, or edit B#7 to replace `fill` by `jsonEncode(fill)`.

`fill` can be any valid JSON value (primitives, arrays, prefilled arrays, dictionaries, etc...)

Unlike a naive filler, this filler deep-copies `fill`, so you don't have to use `copy()` in your flows. Of course, sometimes this may be undesired behavior. If you want every element in the array to be copied by reference, you must use For-Each (or any other loop).

Rudxain profile: llamalab.com/automate/community/flows/42921

Tags: quirk pad padding JS Javascript Array.prototype.fill Array.from

LICENSE: https://unlicense.org