Update walkThrough.md
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
title: walkThrough
|
title: walkThrough
|
||||||
tags: object,recursion,generator,advanced
|
tags: object,recursion,generator,advanced
|
||||||
firstSeen: 2020-12-31T13:03:15+02:00
|
firstSeen: 2020-12-31T13:03:15+02:00
|
||||||
lastUpdated: 2020-12-31T13:03:15+02:00
|
lastUpdated: 2021-11-15T13:18:18+02:00
|
||||||
---
|
---
|
||||||
|
|
||||||
Creates a generator, that walks through all the keys of a given object.
|
Creates a generator, that walks through all the keys of a given object.
|
||||||
@ -11,7 +11,7 @@ Creates a generator, that walks through all the keys of a given object.
|
|||||||
- Define a generator function, `walk`, that takes an object and an array of keys.
|
- Define a generator function, `walk`, that takes an object and an array of keys.
|
||||||
- Use a `for...of` loop and `Object.keys()` to iterate over the keys of the object.
|
- Use a `for...of` loop and `Object.keys()` to iterate over the keys of the object.
|
||||||
- Use `typeof` to check if each value in the given object is itself an object.
|
- Use `typeof` to check if each value in the given object is itself an object.
|
||||||
- If so, use the `yield*` expression to recursively delegate to the same generator function, `walk`, appending the current `key` to the array of keys. Otherwise, `yield` the an array of keys representing the current path and the value of the given `key`.
|
- If so, use the `yield*` expression to recursively delegate to the same generator function, `walk`, appending the current `key` to the array of keys. Otherwise, `yield` an array of keys representing the current path and the value of the given `key`.
|
||||||
- Use the `yield*` expression to delegate to the `walk` generator function.
|
- Use the `yield*` expression to delegate to the `walk` generator function.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user