Arrays
Data Types
Function will recive N for length of array and point as index to pint at in that array.
For example, function should generate arrays like this for
N = 10, point = 7
[7,6,5,4,3,2,1,0,1,2]
N = 10, point = 4
[4,3,2,1,0,1,2,3,4,5]
function func(N, point) {
let start = 0; // starting position of array
let clonePoint = point; // clone for point to start counting from that number at begining of array
let arr = [...Array(N).keys()] // generate array and fill with 0 to 10
if(!(point > N)) {
arr.forEach((o, index) => {
index < point ? arr[index] = clonePoint-- : arr[index] = start++;
});
return arr;
}
return [];
}
// TODO: Replace examples and use TDD development by writing your own tests
// These are some CW specific test methods available:
// Test.expect(boolean, [optional] message)
// Test.assertEquals(actual, expected, [optional] message)
// Test.assertSimilar(actual, expected, [optional] message)
// Test.assertNotEquals(actual, expected, [optional] message)
// NodeJS assert is also automatically required for you.
// assert(true)
// assert.strictEqual({a: 1}, {a: 1})
// assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]})
// You can also use Chai (http://chaijs.com/) by requiring it yourself
// var expect = require("chai").expect;
// var assert = require("chai").assert;
// require("chai").should();
describe("Solution", function(){
it("should return specified array format", function(){
let arr = new Array(7,6,5,4,3,2,1,0,1,2)
Test.assertSimilar(func(10, 7), arr);
});
it("should return specified array format", function(){
let arr = new Array(3,2,1,0,1,2,3,4,5,6)
Test.assertSimilar(func(10, 3), arr);
});
});