Here is the problem:
Given an object and a key, write a function that returns an array containing all but the last element of the array located at the given key.
Notes:
- If the array is empty, it should return an empty array.
- If the property at the given key is not an array, it return an empty array.
- If there is no property at the key, it should return an empty array.
My Code:
var obj = {
key: [1, 2, 3]
};
function getAllButLastElementOfProperty(obj, key) {
var arr = []
arr = obj.key.pop()
return obj.key
}
getAllButLastElementOfProperty(obj, 'key') // [1, 2]
Question:
Why does it fail every single repl test including incuding "should return an array containing all but the last element of the array located at key"??