prestudy-week2

Sunghee Kim·2022년 4월 22일
0

Array.slice()

Access two dimensional array with negative index

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);

Array.pop()

The pop() method removes the last element from an array and returns that element. This method changes the length of the array.

Array.shift()

The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.

profile
개발하는 스트롱맘

0개의 댓글