js practice function most value

js practice function most value

let read =require("readline-sync");
console.log("输入数组长度")
let length = parseInt(read.question(""))
let arr=[]
for (let i=0;i<length;i++) {
    console.log(`请输入第${i+1}个数`)
    let num =Number(read.question(""))
    arr[i]=num
}
function getnum(arr,func){
    let newArr=[];
    for(let i=0;i<arr.length;i++){
        newArr[i]=arr[i];
    }
    newArr.sort(function(A, B) {
         return A- B; 
    }); 
    Switch (FUNC) {
         Case . 1 :
             return newArr [0 ];
             BREAK ; 
    
        Case 2 :
             return newArr [-newArr.length. 1 ];
             BREAK ; 
    } 
} 
the console.log ( "minimum value of the array:", getnum (ARR,. 1 )) 
the console.log ( "maximum value of the array:", getnum (ARR, 2 )) 
the console.log ( "this array is:", arr)

 

Guess you like

Origin www.cnblogs.com/gao7/p/11122012.html