SOURCE

// function maxLessThanN(numbers,n){
//     let maxNumber = -Infinity;
//     for(let i =0;i<numbers.length;i++) {
//         if(numbers[i] < n) {
//             maxNumber = Math.max(maxNumber, numbers[i]);
//         }
//     }
//     return maxNumber
// }

function maxLessThanN(numbers,n){
    let nums = numbers.filter((item) => item < n);
    return nums.length > 0 ? Math.max(...nums) : null;
}


const numbers = [10,20,30,5,3,50];
const n = 25;
const max = maxLessThanN(numbers, n);
console.log(max);
console 命令行工具 X clear

                    
>
console