function processData(n, a, b) { var ans = []; if (a == b) { for (var i=0; i<n+1; i++) { ans.push(a * n); } return ans; } else if (a > b) { var temp = a; a = b; b = temp; } var diff = b - a; for (var i=0; i<n+1; i++) { ans.push(a * n + diff * i); } return ans; }
Well, this is by far the most effective solution. I just tested it on fiddle .
All the other three solutions are significantly superior to yours. Mine is better than @ abc123 because there is no need for sorting and better than @georg because there is no need to use a set or sort.
source share