[removed] Using reduce() to find min and max values?

后端 未结 11 580
野性不改
野性不改 2020-12-09 15:46

I have this code for a class where I\'m supposed to use the reduce() method to find the min and max values in an array. However, we are required to use only a single call to

11条回答
  •  -上瘾入骨i
    2020-12-09 16:10

    const values = [1,2,3,4,5];
    const [first] = values;
    const maxValue = values.reduce((acc, value) => Math.max(acc, value), first);
    

提交回复
热议问题