Niuke brush questions Day3

1. Please complete the JavaScript function, which is required to return the integer part of the number parameter

function _int(value) {
    // 补全代码
  return Math.floor(value)  
}

Parsing: The Math.floor() method performs a rounding down calculation, which returns the nearest integer that is less than or equal to the function parameter

2. Please complete the JavaScript function, which requires the parameter array to be reversed and returned

function _reverse(array) {
    // 补全代码
      let newArr=[]
    for (let i=array.length-1;i>=0;i--) {
        newArr.push(array[i])
    }
     return newArr
}

3. Please complete the JavaScript function, which requires converting the parameter array into a string output.

function _join(array) {
    // 补全代码
       return array.join('')
}

Parsing: This function accepts an array parameter and  join concatenates the array elements into a string through the method. By default,  join a comma is used as the delimiter, but you can pass in other strings as the delimiter. For example, if you want to use spaces as delimiters

4. Please complete the JavaScript function, which is required to find the maximum value in the array parameters and return it.

function _max(array) {
    // 补全代码
     let max=array[0]
     for(let i=1;i<array.length;i++){
         if(max<array[i]){
             max=array[i]
         }
     }
    return max
}

5. Please complete the JavaScript function and request whether the string parameter contains a number in the form of boolean


function _search(string) {
    // 补全代码
   for(let i=0;i<string.length;i++){
       if(typeof(string[i]=='number')){
           return true
       }
       return false
   }
}

Guess you like

Origin blog.csdn.net/weixin_64965154/article/details/130990122