array builtins
Some checks failed
Build / build (push) Successful in 14m31s
Test / build (push) Failing after 17m13s

This commit is contained in:
Chuck Smith
2024-03-24 16:29:18 -04:00
parent 3c66b980e7
commit fea9fb9f64
13 changed files with 197 additions and 34 deletions

21
builtins/sorted.go Normal file
View File

@@ -0,0 +1,21 @@
package builtins
import (
"monkey/object"
"sort"
)
// Sorted ...
func Sorted(args ...object.Object) object.Object {
if len(args) != 1 {
return newError("wrong number of arguments. got=%d, want=1",
len(args))
}
if a, ok := args[0].(*object.Array); ok {
newArray := a.Copy()
sort.Sort(newArray)
return newArray
}
return newError("argument #1 to `sorted` expected to be `array` got=%T", args[0].Type())
}