Start a new topic

How do I generate a sequence from a min and max value input?

//generates sequence of integers from min/max value

function(){ var list = []; for (var i = parseInt(x0); i <= parseInt(x1); i++) { list.push(i); } return(list); }()


1 Comment

I like linspace:

function linspace(a,b,n) {
    if(typeof n === "undefined") n = Math.max(Math.round(b-a)+1,1);
    if(n<2) { return n===1?[a]:[]; }
    var i,ret = Array(n);
    n--;
    for(i=n;i>=0;i--) { ret[i] = (i*b+(n-i)*a)/n; }
    return ret;
}

 from: https://gist.github.com/joates/6584908

Login to post a comment