Example 1 — Official: Remove One Level
The two samples from the Ramda docs: a mixed list, and a list of pairs.
console.log(R.unnest([1, [2], [[3]]])); // [1, 2, [3]]
console.log(R.unnest([[1, 2], [3, 4], [5, 6]])); // [1, 2, 3, 4, 5, 6] How It Works
- Plain item.
1is not a list, so it is copied as it is. - One wrap.
[2]becomes2, and[[3]]becomes[3]— only the outer brackets go. - Pairs. Each pair in the second list is opened, and the numbers are joined in order.
- New array. Both calls return new arrays; the inputs are not changed.
