function generateInterval(start, stop, step) { const arr = []; let value = start; for (let index = 0; index <= (stop - start) / step; index++) { arr.push(value); value += step; } return arr; }
// Since Node 10, we're using Mocha. // You can use `chai` for assertions. const chai = require("chai"); const assert = chai.assert; const Test = require("@codewars/test-compat"); describe("generateInterval(2, 10, 2)", function() { it("startLessThenStop", function() { Test.assertSimilar(generateInterval(2, 10, 2), [2, 4, 6, 8, 10]); }); }); describe("generateInterval(2, 10, -2)", function() { it("startBiggerThenStop", function() { Test.assertSimilar(generateInterval(2, -10, -2), [2,0,-2,-4,-6,-8,-10]); }); });