본문 바로가기
codes/고차 함수

15_getDoubledElements

by Mia_ 2022. 11. 20.
function getDoubledElements(arr) {
  //Q. 수를 요소로 갖는 배열을 입력받아 각 요소를 2배 곱한 새로운 배열 리턴
  //주의! map() 사용 필수!

  const double = function(ele){
    return ele * 2;
  }

  return arr.map(double);
}
//다시 풀어본 코드
function getDoubledElements(arr) {
  //Q. 수를 요소로 갖는 배열을 입력받아 각 요소를 2배 곱한 새로운 배열을 리턴
  //map() 필수 사용!

  return arr.map(function(el){
    return el * 2;
  });

}

'codes > 고차 함수' 카테고리의 다른 글

17_checkEvenOrNot  (0) 2022.11.20
16_getLengthOfElements  (0) 2022.11.20
14_getElementsLessThan100AtProperty  (0) 2022.11.20
13_getIndex  (0) 2022.11.20
12_filterOddLengthWords  (0) 2022.11.20