Skip to content

Instantly share code, notes, and snippets.

@tdd
Last active November 17, 2015 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdd/e4590fb0df97d9f88872 to your computer and use it in GitHub Desktop.
Save tdd/e4590fb0df97d9f88872 to your computer and use it in GitHub Desktop.
splice exo
var items;
// insertAt //////////////////////////////////
function insertAt(arr, pos, item) {
}
items = ['one', 'two', 'three'];
console.assert(insertAt(items, 1, 'yo') === 4);
console.assert(items[1] === 'yo');
// deleteAt //////////////////////////////////
function deleteAt(arr, pos, count) {
}
items = ['one', 'two', 'three', 'four'];
var result = deleteAt(items, 1, 2);
console.assert(result.length === 2);
console.assert(items[0] === 'one');
console.assert(items[1] === 'four');
console.assert(result[0] === 'two');
console.assert(result[1] === 'three');
// multiShift //////////////////////////////////
function multiShift(arr, count) {
}
items = ['one', 'two', 'three']
result = multiShift(items, 2);
console.assert(result.length === 2);
console.assert(result[0] === 'one');
console.assert(result[1] === 'two');
console.assert(items.length === 1);
console.assert(items[0] === 'three');
// multiPop //////////////////////////////////
function multiPop(arr, count) {
}
items = ['one', 'two', 'three', 'four', 'five', 'six']
result = multiPop(items, 2);
console.assert(result.length === 2);
console.assert(result[0] === 'five');
console.assert(result[1] === 'six');
console.assert(items.length === 4);
console.assert(items[0] === 'one');
console.assert(items[1] === 'two');
console.assert(items[2] === 'three');
console.assert(items[3] === 'four');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment