mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-22 09:37:17 +00:00
Add spliceIn utility function
This commit is contained in:
parent
9c993a2646
commit
c2588292ce
2 changed files with 21 additions and 1 deletions
|
|
@ -187,3 +187,9 @@ export const filterObject = (obj, predicate) =>
|
|||
}
|
||||
return newObj;
|
||||
}, {});
|
||||
|
||||
export const spliceIn = (original, start, newValues) => {
|
||||
const newArr = [...original];
|
||||
newArr.splice(start, 0, ...newValues);
|
||||
return newArr;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ import {
|
|||
normalize,
|
||||
denormalize,
|
||||
segment,
|
||||
moveSelected
|
||||
moveSelected,
|
||||
spliceIn
|
||||
} from "./utils";
|
||||
|
||||
const fixture = filename =>
|
||||
|
|
@ -215,3 +216,16 @@ describe("moveSelected", () => {
|
|||
expect(moveSelected(arr, i => arr[i], -1)).toEqual([false, true, false]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("spliceIn", () => {
|
||||
it("is immutable", () => {
|
||||
const original = [1, 2, 3];
|
||||
const spliced = spliceIn(original, 1, [200]);
|
||||
expect(spliced).not.toBe(original);
|
||||
expect(original).toEqual([1, 2, 3]);
|
||||
});
|
||||
it("adds values at the given index", () => {
|
||||
const spliced = spliceIn([1, 2, 3], 1, [200]);
|
||||
expect(spliced).toEqual([1, 200, 2, 3]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue