What is between?

Lee·2022년 8월 10일

Algorithm

목록 보기
68/92
post-thumbnail

❓ What is between?

Q. Complete the function that takes two integers (a, b, where a < b) and return an array of all integers between the input parameters, including them.

For example:

a = 1
b = 4
--> [1, 2, 3, 4]

✔ Solution

//#my solution
function between(a, b) {
  // your code here
  let arr = [];
  for(let i = a; i<=b; i++){
    arr.push(i);
  }
  return arr;
}

//#other solution
const between = (a, b) =>
  [...Array(b - a + 1)].map((_, idx) => idx + a);
}
profile
Lee

0개의 댓글