프로그래밍/JavaScript
19.11.27) JS - checkio 속 유용한 메소드
DevJun
2019. 12. 14. 21:04
str
replace(arg1, arg2), chatAt(index), endsWith(), startsWith() includes(), indexOf(), toLowerCase(), toUpperCase()
array
- endsWith(), startsWith(), includes(), indexOf()
- splice() 배열 원소 삭제할 때!
isNaN()
sort() 이용해서 객체나 정수 배열 내림, 오름차순 만들기
// 배열에 담긴 상품(객체)의 가격 중 큰 것을 limit만큼 출력
function biggerPrice(limit, data) {
const answer = [];
data.sort(function(a, b){
return b.price - a.price;
})
for(let i =0; i<limit; i++){
answer.push(data[i]);
}
return answer;
}