Is there a way to generate sequence of characters or numbers in javascript?
For example, I want to create array that contains eight 1s. I can do it with for loop, bu
If like me you use linspace a lot, you can modify your version of linspace easily like so:
function linSeq(x0, xN) {
return linspace(x0, xN, Math.abs(xN-x0)+1);
}
function linspace(x0, xN, n){
dx = (xN - x0)/(n-1);
var x = [];
for(var i =0; i < n; ++i){
x.push(x0 + i*dx);
}
return x;
}
You can then use linSeq in any direction, e.g. linSeq(2,4) generates 2,3,4 while linSeq(4,2) generates 4,3,2.