2018-4-25 Qingteng Cloud Front-end Development Interns Written Test 1. It is a puzzle, about how much money a boss will lose when he receives counterfeit money , the first two are easier 3. Reorder the js array randomly

1. It's a puzzle, about how much money a boss will lose when he receives counterfeit bills

2. 囧, it is a regular puzzle. In general, the first two are relatively easy

3. Reorder the js array randomly

function randomArr(arr){
    var _arr = [];
    var length = arr.length;
    for(var i=0; i<length; i++){
        var random = Math.random() * arr.length;
        _arr.push(arr.splice(random, 1)[0]);
    }
    return _arr;
}

4. Use C language and the minimum time efficiency and space to realize a string inversion to an inverted string, that is, the classical algorithm of C language - the inversion of a string

void Reverse(char s[])
{
     for(int i =0,j=strlen(s)-1;i<j; ++i,--j)
     {
        char c=s[i];
        s[i]=s[j];
        s[j]=c;
     }
}
This function is originally from the second edition of the classic work TCPL by Kernighan and Ritchie
Comment: This algorithm should be optimal in terms of time complexity and minimum space usage.
It only takes half the time to traverse the length of the string in time, and only creates the length of the string in space.
half the space. Of course, we can further reduce the use of space.
void Reverse(char s[])
{
    char c;
    for(int i =0,j=strlen(s)-1;i<j; ++i,--j)
     {
        c=s[i];
        s[i]=s[j];
        s[j]=c;
     }
}
We declare c externally so that we only use one variable throughout the string reversal. space usage
Smaller! But one problem we have to consider is that when the string we pass uses only one character,
The above algorithm is not as efficient as the first algorithm, because the above function creates one more unused one.
char objects, and the C++ language recommends: "Delay variable declarations as much as possible". So really I still agree to use "TCPL"
The above method is used to define the form of char c=s[i]!

5. Briefly describe the compilation on the chrome client after writing const = 4 in the js language


6. Use js language to classify the elements in the array according to their attributes

Detailed explanation of array objects in JavaScript - short book https://www.jianshu.com/p/fd8c73d2cf2c


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324865338&siteId=291194637