var ops = { 
  "plus": (x,y)=>x+y,
  "mul" : (x,y)=>x*y,
  "and" : (x,y)=>x&y
}

function operation(op, array) {
  return array.slice(1).reduce(ops[op], array[0]);
} 

operation("plus", array);
operation("mul",  array);
operation("and",  array); 

 

相关文章:

  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
  • 2021-12-21
  • 2021-11-07
  • 2021-11-17
  • 2021-12-03
猜你喜欢
  • 2022-12-23
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2021-12-19
  • 2022-12-23
相关资源
相似解决方案