Assignment
array 감옥에 갇힌 2를 구해주세요.
단, slice 메서드를 사용해야 하며, slice 메서드 괄호 안에는 음수만 들어갈 수 있습니다.
let prisoners = [[0, 1],[1,2],[0,0]];
saveNumberTwo(prisoners) // 2
내가 쓴 코드
let prisoners=[[0,1],[1,2],[0,0]];
function saveNumberTwo(arr){
let temp=arr.slice(-2,-1)//[[1,2]]
let answer=temp[0][1]//2
return answer;
}
saveNumberTwo(prisoners);
The pop() method removes the last element from an array and returns that element. This method changes the length of the array.
The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.