柯里化

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>

function a(m) {
  return m * 2
}    
function b(m) {
  return m + 2
}    
function c(m) {
  return m - 12
}    
function d(m) {
  return m / 2
}
function compose(temp, arr) {
  let res = temp
  arr.map(item => {
    res = item(res)
  })
  return res;
}
console.log(compose(2, [a, b, c, d]))

</script>
</body>
</html>

评论

暂无评论