61890b15cb
* wip * move print and JSON functions to modules * builtin functions are not replacable now * builtin functions are added for default nil symbol table * importables: builtin modules and source modules * refactoring runtime tests * fix tests * update documentation * cleanup * clean up cli * fix REPL prints
40 lines
964 B
Text
40 lines
964 B
Text
export {
|
|
// all returns true if the given function fn evaluates to a truthy value on
|
|
// all of the items in the enumerable.
|
|
all: func(enumerable, fn) {
|
|
for k, v in enumerable {
|
|
if !fn(k, v) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
},
|
|
// any returns true if the given function fn evaluates to a truthy value on
|
|
// any of the items in the enumerable.
|
|
any: func(enumerable, fn) {
|
|
for k, v in enumerable {
|
|
if fn(k, v) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
},
|
|
// chunk returns an array of elements split into groups the length of size.
|
|
// If the enumerable can't be split evenly, the final chunk will be the
|
|
// remaining elements.
|
|
chunk: func(enumerable, size) {
|
|
numElements := len(enumerable)
|
|
|
|
if !numElements {
|
|
return []
|
|
}
|
|
|
|
res := []
|
|
idx := 0
|
|
for idx < numElements {
|
|
res = append(res, enumerable[idx:idx+size])
|
|
idx += size
|
|
}
|
|
return res
|
|
}
|
|
}
|