Last active
November 17, 2015 10:04
-
-
Save tdd/e4590fb0df97d9f88872 to your computer and use it in GitHub Desktop.
splice exo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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