functionminiMaxSum(arr){// Write your code hereconstsortedArray=arr.sort();letmin_sum=0letmax_sum=0for(leti=0;i<arr.length;i++){if(i<arr.length-1){min_sum+=arr[i]}if(i>0){max_sum+=arr[i]}}console.log(min_sum,max_sum)}
function miniMaxSum(arr) {
// Write your code here
const max = arr.sort((a,b) => b-a).slice(0,4).reduce((a,b)=> a+b,0)
const min = arr.sort((a,b) => b-a).reverse().slice(0,4).reduce((a,b)=> a+b,0)
console.log(min,max)
}
Experienced Full Stack Developer with expertise in Laravel, Vue.js, Wordpress, HTML, CSS, JavaScript, PHP and MySQL.. My articles here will always be precise and short to the point, that's my style.
Top comments (5)
this.guy().is().doing().functional-programming()
This is great, i also solved this using PHP ( Mini-Max Sum Solution using PHP) incase someone needs that.
Nice to meet you great job