Pattern: Unexplained depth in Array#flat()
Issue: -
Using magic numbers for the Array#flat()
depth parameter makes code harder to understand. Common values are 1
(default) and Infinity
. When using other values, add a comment explaining the depth.
Example of incorrect code:
array.flat(2);
array.flat(20);
Example of correct code:
array.flat(2 /* for nested arrays of json responses */);
array.flat(1);
array.flat();
array.flat(Infinity);