푸린세스

고차함수 2 리턴값이 함수인경우. 본문

프론트/자바스크립트

고차함수 2 리턴값이 함수인경우.

푸곰주 2023. 5. 30. 14:31
function isBetween(num){
    return num>=50 && num<=100
}
function isBetween2(num){
    return num>=1 && num<=10
}

//팩토리함수 :함수를 반환하는데 이름이없다. 그냥 값으로 전달됨.
//  함수를 만들어주는 함수
// min, max전달 시 각기다른 새로운함수 반환
function makeBetweenFunc(min, max){
    return function(num){
        return num >= min && num<=max;
    }
}
const isChild = makeBetweenFunc(0,18)
isChild(19)
//false
isChild(5)
//true
const isAudlt = makeBetweenFunc(19,64);

const isSenior = makeBetweenFunc(65,120);