Closed harryworld closed 10 years ago
removeAt = (array, num) ->
array.splice(num-1, 1)
array
console.log removeAt [25, 33, 6, 2, 3], 2
testArray = [1...10] removeAt = (array, n) -> array.splice(n-1,1)
removeAt testArray, 4 console.log testArray
removeAt = (array, n) ->
array.splice(n-1, 1)
array
arrayOne = [25, 33, 6, 2, 3]
console.log removeAt arrayOne, 2
#-> [25, 6, 2, 3]
removeAt = (array, n) -> array.splice(n-1, 1) array
removeAt = (array, n) -> array.splice(n-1,1) array
arrayTest = [25, 33, 6, 2, 3]
console.log removeAt(arrayTest, 2)
removeAt = (array, n) ->
array.splice(n-1, 1)
array
console.log removeAt([25, 33, 6, 2, 3], 2)
removeAt = (array, n) -> array.splice(n-1,1) array
arrayTest = [25, 33, 6, 2, 3]
console.log removeAt(arrayTest, 2)
array = [25, 33, 6, 2, 3]
removeAt = (array, 1) -> array.splice(pos-1, 1) array
removeAt(array, 2)
==OR===
array = [25, 33, 6, 2, 3]
removeAt = (array, pos, howmany) -> array.splice(pos-1, howmany) array
removeAt(array, 2, 1)
Array = [25, 33, 6, 2, 3]
removeAt = (array, n) -> array.splice(n-1, 1)
removeAt(array, n)
removeAt = (array, n) -> array.splice(n-1, 1) array console.log removeAt([25, 33, 6, 2, 3], 2)
removeAt = (array, n) ->
array.splice(n - 1, 1)
array
console.log removeAt([25, 33, 6, 2, 3], 2)
In javascript:
removeAt = function(array, n) { for(var i = array.length; i >= 0; i--) { if(array[i] === n) { array.splice(i, 1); }; }; return array }
hello = [1, 2, 3];
removeAt(hello, 2);
Write a function called
removeAt
that takes two arguments: an array and a number n. The function should return an array with the element at the nth position removed.