relu-core
Version:
57 lines (40 loc) • 1.23 kB
JavaScript
var rp = require("../");
var array = rp.variable([
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
"test", "foo", "boo"
]);
var limit = rp.variable(7);
var smallNumbers = array.filter(function(item) {
return typeof item === "number" && item < limit();
});
var sum = smallNumbers.reduce(function(a, b) {
return a + b;
});
rp.ever(function() {
var msg = rp.const("The array has ").plus(array.size()).plus(" elements");
console.log("Message: " + msg());
});
// logs: The array has 13 elements
rp.ever(function() {
console.log("The small numbers are: " + smallNumbers().join(", "));
});
// logs: The small numbers are: 1, 2, 3, 4, 5, 6
rp.ever(function() {
console.log("The sum is: " + sum());
});
// logs: The sum is: 21
array.push(11);
// logs: The array has 14 elements
array.push("zZzZ");
// logs: The array has 15 elements
array.push(-1);
// logs: The array has 16 elements
// logs: The small numbers are: 1, 2, 3, 4, 5, 6, -1
// logs: The sum is: 20
array.push(0);
// logs: The array has 17 elements
// logs: The small numbers are: 1, 2, 3, 4, 5, 6, -1, 0
array.set([5, 10]);
// logs: The array has 2 elements
// logs: The small numbers are: 5
// logs: The sum is: 5