rewrite expand

This commit is contained in:
filifa 2024-07-11 21:50:07 -05:00
parent 8d509bf71a
commit 8b8ab675bd
1 changed files with 8 additions and 2 deletions

View File

@ -37,8 +37,14 @@ type about struct {
}
func expand(arr []any, idx int) []any {
front := append(arr[:idx], nil)
all := append(front, arr[idx:])
var all []any
if idx < len(arr) {
all = arr
} else {
all = make([]any, idx+1)
copy(all[:len(arr)], arr)
all[idx] = make(map[string]any)
}
return all
}