Skip to content

Commit

Permalink
refactor: adding more examples for flat function
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaban-Eissa committed May 26, 2024
1 parent 679ccac commit 5264f82
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions 3.implement-Array.prototype.flat.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,11 @@ Could you manage to implement your own one?
Here is an example to illustrate

```js
const arr = [1, [2], [3, [4]]];

flat(arr);
// [1, 2, 3, [4]]

flat(arr, 1);
// [1, 2, 3, [4]]

flat(arr, 2);
// [1, 2, 3, 4]

flat(arr, Infinity);
// [1, 2, 3, 4]
console.log(flat([1, [2, [3, [4, [5]]]]], 1)); // [1, 2, [3, [4, [5]]]
console.log(flat([1, [2, [3, [4, [5]]]]], 2)); // [1, 2, 3, [4, [5]]
console.log(flat([1, [2, [3, [4, [5]]]]], 3)); // [1, 2, 3, 4, [5]
console.log(flat([1, [2, [3, [4, [5]]]]], 4)); // [1, 2, 3, 4, 5]
console.log(flat([1, 2, 3, [4, 5, [6, 7, 8, [9, 10]]]], Infinity)) // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
```

follow up
Expand Down

0 comments on commit 5264f82

Please sign in to comment.