0
Listing top five numbers
I have a google Scripts application that takes data from a third-party application and puts is onto Google sheets. Now I want to make a function that has one parameter being any integer from 1 to 10. The function will then take numbers from the sheet and order it from highest to lowest and output the top many of numbers asked by the user. I just don’t know how I’m going to go about making that function. Any suggests would appreciated!
2 Respuestas
+ 3
example:
const myArray = [1,3,4,5,2,5,3,7,8,0];
function giveTop(array,top) {
return array.sort((a, b) => b - a).slice(0,top);
}
giveTop(myArray, 5); // output: [ 8, 7, 5, 5, 4 ]
+ 1
You can grab the numbers from the sheet and short it using any shorting alogorithm like Buble-short, Hip-short or Merge-short and so on.