Q:

Write a JavaScript program to return the minimum-maximum value of an array, after applying the provided function to set comparing rule

0

Write a JavaScript program to return the minimum-maximum value of an array, after applying the provided function to set comparing rule.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const reduce_Which = (arr, comparator = (a, b) => a - b) =>
  arr.reduce((a, b) => (comparator(a, b) >= 0 ? b : a));
console.log(reduce_Which([1, 3, 2])); 
console.log(reduce_Which([10, 30, 20], (a, b) => b - a));  
console.log(reduce_Which(
  [{ name: 'Kevin', age: 16 }, { name: 'John', age: 20 }, { name: 'Ani', age: 19 }],
  (a, b) => a.age - b.age)); 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now