function filterOddLengthWords(words) {
//Q. 문자를 요소로 갖는 배열을 받아 그 길이가 홀수인 요소만을 갖는 배열 리턴
//주의! filter() 사용 필수
//let output = filterOddLengthWords(['there', 'it', 'is', 'now']);
//console.log(output); // --> ['there', "now']
//이 조건이 참이되도록 문자열의 길이가 홀수이도록
const oddLength = function(words){
return words.length % 2 !== 0;
}
return words.filter(oddLength);
}
//다시 풀어본 코드
function filterOddLengthWords(words) {
//Q. 문자를 요소로 갖는 배열을 받아 그 길이가 홀수인 요소만을 갖는 배열 리턴
//주의! filter() 사용 필수
//let output = filterOddLengthWords(['there', 'it', 'is', 'now']);
//console.log(output); // --> ['there', "now']
return words.filter(function(el){
return el.length % 2 !== 0;
});
}
'codes > 고차 함수' 카테고리의 다른 글
14_getElementsLessThan100AtProperty (0) | 2022.11.20 |
---|---|
13_getIndex (0) | 2022.11.20 |
11_keep (0) | 2022.11.20 |
10_removeElment (0) | 2022.11.20 |
09_filterCallback (0) | 2022.11.20 |