Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getIn(o, path) {
- if (path.length === 0) return o
- if (typeof o !== 'object') return
- return get(o[path[0]], path.slice(1, path.length))
- }
- function setIn(o, path, v) {
- let count = 0
- let parent = o
- while (count < path.length) {
- const current = getIn(o, path.slice(0, count + 1))
- if (typeof current === 'object') {
- parent = current
- } else {
- parent[path[count]] = {}
- parent = parent[path[count]]
- }
- count++
- }
- parent[path[count - 1]] = v
- return o
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement