( obj: Object | Array<any>, path: Array<string | number>, index: number = 0, )
| 53 | } |
| 54 | |
| 55 | export function copyWithDelete( |
| 56 | obj: Object | Array<any>, |
| 57 | path: Array<string | number>, |
| 58 | index: number = 0, |
| 59 | ): Object | Array<any> { |
| 60 | const key = path[index]; |
| 61 | const updated = isArray(obj) ? obj.slice() : {...obj}; |
| 62 | if (index + 1 === path.length) { |
| 63 | if (isArray(updated)) { |
| 64 | updated.splice(((key: any): number), 1); |
| 65 | } else { |
| 66 | delete updated[key]; |
| 67 | } |
| 68 | } else { |
| 69 | // $FlowFixMe[incompatible-use] number or string is fine here |
| 70 | updated[key] = copyWithDelete(obj[key], path, index + 1); |
| 71 | } |
| 72 | return updated; |
| 73 | } |
| 74 | |
| 75 | // This function expects paths to be the same except for the final value. |
| 76 | // e.g. ['path', 'to', 'foo'] and ['path', 'to', 'bar'] |
no test coverage detected