Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 527
add flatten function#684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
add flatten function #684
Changes from all commits
a880eeab83d632674c94f4f0a28bbba1e30File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -359,3 +359,17 @@ func median(args ...any) ([]float64, error) { | ||
| } | ||
| return values, nil | ||
| } | ||
| func flatten(arg reflect.Value) []any { | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice job! No need to extra .Interface() call. 👍🏻 | ||
| ret := []any{} | ||
| for i := 0; i < arg.Len(); i++ { | ||
| v := deref.Value(arg.Index(i)) | ||
| if v.Kind() == reflect.Array || v.Kind() == reflect.Slice { | ||
| x := flatten(v) | ||
| ret = append(ret, x...) | ||
| } else { | ||
| ret = append(ret, v.Interface()) | ||
| } | ||
| } | ||
| return ret | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -689,6 +689,14 @@ Concatenates two or more arrays. | ||
| concat([1, 2], [3, 4]) == [1, 2, 3, 4] | ||
| ``` | ||
| ### flatten(array) {#flatten} | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 | ||
| Flattens given array into one-dimentional array. | ||
| ```expr | ||
| flatten([1, 2, [3, 4]]) == [1, 2, 3, 4] | ||
| ``` | ||
| ### join(array[, delimiter]) {#join} | ||
| Joins an array of strings into a single string with the given delimiter. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! As flatten creates a new array it makes sense to safe from uncontrolled grow.