Just include it.

require("./from");

var n = 100;
var primeNumbers = [2];

isPrime = function(n) {
    return !$range(3, n + 1, 2).takeWhile("$ * $ <= @", n).any("@ % $ == 0", n);
};

$range(3, n + 1, 2).where("isPrime($)").each("@push($)", primeNumbers);

console.log("Prime numbers < " + n + ": " + primeNumbers.join(" "));

// Prime numbers < 100: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Last edited Jun 8, 2012 at 12:41 AM by suckgamoni, version 2

Comments

No comments yet.