当前位置:网站首页>typeScript - Partially apply a function

typeScript - Partially apply a function

2022-08-04 23:58:00 MXM_777

function IsgoodNumber(a:number,v:number){

return v % a ===0

}

function filterArray(a:number[],f:(a:number,b:number)=>boolean){

return a.filter(f)

}

//Example

function ccc(f:(a:number,b:number)=>boolean,a:number){

return (b:number)=>{

return f(a,b)//a is a free variable

}

}

const goodnum =3

const a = [1,2,3,4,56,7,9]

// console.log(a.filter((v)=> v%2 ===0))

console.log(

filterArray(a,(v)=>IsgoodNumber(goodnum,v))

)

// console.log(

// filterArray(a,ccc(IsgoodNumber,goodnum))

// )


原网站

版权声明
本文为[MXM_777]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/216/202208042243523400.html