When a function accepts a single or multiple things. Though [foo].flat()
is shorter and nicer, but it's not very clear to me.
I prefer Array.isArray(foo) ? foo : [foo]
. If the array need to be cloned Array.isArray(foo) ? [...foo] : [foo]
.
But if the variable name is something like nameOrNames
, [nameOrNames].flat()
looks clear to me, maybe we can add an exception.
items = [items].flat();
items = Array.isArray(items) ? items : [items];
items = Array.isArray(items) ? [...items] : [items];
items = [...(Array.isArray(items) ? items : [items])];
const names = [nameOrNames].flat();
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too