do similar array copy at end of recursion

This commit is contained in:
filifa 2024-07-10 23:30:59 -05:00
parent 542c2850a7
commit 8603978c7d
1 changed files with 7 additions and 4 deletions

View File

@ -54,11 +54,14 @@ func patch(obj any, path string, value any) error {
break break
} }
if idx < len(v) { if len(v) <= idx {
v[idx] = value arr := make([]any, idx+1)
} else { for i, val := range v {
v = append(v, value) arr[i] = val
}
v = arr
} }
v[idx] = value
default: default:
err = errors.New("couldn't determine type") err = errors.New("couldn't determine type")
} }