범위를 지정하여 정확히 두 개의 숫자 배열을 취하는 JavaScript 함수를 작성해야 합니다.
함수는 인수로 지정된 범위(둘 다 포함)에 속하는 임의의 정수를 생성해야 합니다.
예시
const range = [5, 15];
const randomBetween = ([min, max]) => {
// +1 to include the max range const random = Math.random() * (max - min + 1);
const whole = Math.floor(random) + min;
return whole;
};
for(let i = 0; i < 10; i++){
console.log(randomBetween(range));
} 출력
콘솔의 출력은 -
13 10 6 10 12 5 14 13 11 6
이 출력은 실행할 때마다 변경될 수 있습니다.