Files
monkey/object/builtin_last.go
Chuck Smith 43362475f9
Some checks failed
Build / build (push) Successful in 10m0s
Test / build (push) Failing after 16m20s
seperated builtins
2024-03-20 17:01:45 -04:00

22 lines
404 B
Go

package object
// Last ...
func Last(args ...Object) Object {
if len(args) != 1 {
return newError("wrong number of arguments. got=%d, want=1",
len(args))
}
if args[0].Type() != ARRAY_OBJ {
return newError("argument to `last` must be ARRAY, got %s",
args[0].Type())
}
arr := args[0].(*Array)
length := len(arr.Elements)
if length > 0 {
return arr.Elements[length-1]
}
return nil
}