Merge pull request #753 from 30-seconds/feature/shank

[FEATURE] shank()
This commit is contained in:
Angelos Chalaris
2018-09-27 18:12:10 +03:00
committed by GitHub
5 changed files with 62 additions and 0 deletions

5
test/shank/shank.js Normal file
View File

@ -0,0 +1,5 @@
const shank = (arr, index = 0, delCount = 0, ...elements) =>
arr.slice(0, index)
.concat(elements)
.concat(arr.slice(index + delCount));
module.exports = shank;

22
test/shank/shank.test.js Normal file
View File

@ -0,0 +1,22 @@
const expect = require("expect");
const shank = require("./shank.js");
test("shank is a Function", () => {
expect(shank).toBeInstanceOf(Function);
});
const names = ['alpha', 'bravo', 'charlie'];
test("Returns an array with the added elements.", () => {
expect(shank(names, 1, 0, 'delta')).toEqual(['alpha', 'delta', 'bravo', 'charlie']);
});
test("Returns an array with the removed elements.", () => {
expect(shank(names, 1, 1)).toEqual(['alpha', 'charlie']);
});
test("Does not mutate the original array", () => {
shank(names, 1, 0, 'delta');
expect(names).toEqual(['alpha', 'bravo', 'charlie']);
});