prestudy-Week2

Sunghee Kim·2022년 4월 24일
0

splice()

The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place

splice(start)
splice(start, deleteCount)
splice(start, deleteCount, item1)
splice(start, deleteCount, item1, item2, itemN)

Assignment

기념사진을 찍으려고 하는데, 키 큰 사람들이 앞으로 나와있습니다.
splice method를 이용해 175cm 이상인 사람은 뒤에 설 수 있도록 코드를 작성해주세요.
(단, splice 메서드 괄호 안에는 무조건 음수만 적용해야 합니다)

let lane1 = [{'철수':'150cm'}, {'영희': '153cm'}, {'바둑이': '155cm'},{'밍키': '160cm'}, {'살구' : '168cm'}, {'두팔': '175cm'}, {'여름': '180cm'}, {'소헌': '181cm'}];

extractOver175(lane1) // [{'두팔': '175cm'}, {'여름': '180cm'}, {'소헌': '181cm'}];

function extractOver175(list) {
let extractedPeople = list.splice(-3)
return extractedPeople;
}

profile
개발하는 스트롱맘

0개의 댓글