In the last three months, I have been working in front end, Java backend, client r&d and algorithm positions frequently. In order to improve the efficiency of interview, I have been optimizing my interview process and skills, instead of separating the algorithm from the foundation like traditional interview.
Algorithm 1: Using recursive Fibonacci sequence
I was surprised to find that more than half of the students who came for the interview did not know about front-end, back-end, and client r&d. Maybe it was because 996 students were busy with business r&d and neglected the basics.
Fibonacci sequence the Fibonacci sequence, also known as the Golden section sequence, is a sequence of numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34.
In mathematics, Fibonacci sequence in the following definition of recursive method: F (1) = 1, F (2) = 1, F (n) = F (n – 1) + F (n – 2) (n > = 3, n ∈ n *).
An interviewer who understands the concept can easily write an implementation of the recursion:
function fib(n){
if(n==1||n==2){
return 1;
}
returnfib(n-1)+fib(n-2);         }Copy the code
Even if you don’t know the concept of the sequence, you can write most of it with a hint, but as an interview, not only that, I usually go further and remind them to implement it in a more concise way. The core algorithm requires that only one statement be used to examine its use of the ternary operator:
function fib(n){
returnn < 3 ? 1 : fib(n-1)+fib(n-2);         }Copy the code
Then, I will ask fib(n-1)+ FIB (n-2) whether to add (), to investigate his confidence in his code and his mastery of computing priority. Generally, inexperienced JS development will hesitate to confirm whether to add parentheses, whether to add or not, and which is better.
This is not enough for this simple algorithm, so I will continue to ask if there are any questions, and I will give appropriate reminders through code robustness and exception handling to see if the interviewer is aware of the need to judge the input value n. Obviously, n must be a positive integer, so you can examine typeOF to determine a JS variable type, float in JS, etc., by ensuring that n is a positive integer.
function fib(n){
if(typeof n === 'number' && n > 0 && parseInt(n) === n ) {
returnn < 3 ? 1 : fib(n-1)+fib(n-2);   }else {
return 'Input is invalid, please enter a positive integer! '; }      }Copy the code
There are a number of ways to ensure that n is a positive integer. Some want to use indexOf(‘.’), but many are not well thought out. Using it alone will not work because it will filter out 1.000.
After raising the floating point number, I would then ask the question 0.1 + 0.2 === 0.3, which is generally known to most front-end users.
The first algorithm, not only examined JS in the most basic grammar and variables, but also for the next algorithm laid a foible, intelligent potential interviewers, generally will draw inferiorly, the next problem can consider semantic and abnormal processing.
Algorithm 2: Find the maximum value of the difference between two pairs in an array, requiring O(n) time complexity
The time complexity of the subject, the general will be generally the interviewer to ignore, begin sorting, then I will issue a variety of commonly used sorting algorithm’s time complexity, finally found not meet my requirements, open up the analysis problem not directly do the interviewer, after work is particularly easy to develop a moment’s demand, finally found need not products.
Some smart interviewers quickly turn the problem into finding a minimum and a maximum in an array, so they only need to walk through the array once, satisfying the O(n) time requirement.
function maxDiffInArray(arr){
let max = arr[0], min = arr[0];
for (let i = 0; i < arr.length; i++) {
if (arr[i] < min) { min = arr[i]; }
if(arr[i] > max) { max = arr[i]; }}returnmax - min;     }Copy the code
Let const var, scope, closure, etc. I will also ask the interviewer to implement it in fewer sentences.
function maxDiffInArray(arr){
let max = arr[0], min = arr[0];
arr.map(item => max = Math.max(item, max), min = Math.min(item, min));
returnmax - min;     }Copy the code
After the interview is implemented according to my promotion, I will further ask the methods of traversing the number group, and whether the traversing object method can be used to traverse the number group, and what problems will exist. I will also check the degree of their mastery of the arrow function in ES, and the arrow function will lead to the argument object. For the advanced front end, I will also examine the internal principle of a new object. At the same time, I will also examine the reason why ES6 introduces the arrow function to some questions related to this. The more advanced, the deeper the questions will be asked.
Once again, I will remind you how to ensure the robustness of your code and how to handle exceptions. Obviously, you want to make sure that the input is a valid array.
function maxDiffInArray(arr){
if ( arr instanceof Array) {
if (arr.length) {
let max = arr[0], min = arr[0];
for (let i = 0; i < arr.length; i++) {
if( typeof arr[i] ! = ='number' ) {
return 'Invalid input, array has non-numeric elements, please enter numeric array';
}
max = Math.max(arr[i], max), min = Math.min(arr[i], min);
}
returnmax - min;   }else {
return 'Invalid input, array is empty, please enter non-empty array'; }}else {
return 'Invalid input, please enter non-empty array';
} 
}
Copy the code
In this section, we examine several common methods and things to be aware of for determining a variable as an array. We also examine whether the interviewer knows which methods of iterating a set of numbers cannot be separated from iterating. For experienced candidates, I also examine the knowledge of iterators.
conclusion
Through the above two algorithm questions, about half an hour, we can relatively comprehensive investigation of the interviewee’s JS foundation, programming logic, thinking rigour, and coding habits, can also judge the personality characteristics of the interviewee, and even inspect his English vocabulary.
Only when the above survey answers almost completely, I will further investigate H5 and CSS things, framework and project experience is generally 5 minutes to understand. At the same time, we also pay more attention to its grasp of front-end client technology, see if it has a blog and Github, from its self-driven learning and self-learning knowledge and skills, to infer its potential!
The above is just a case of the front end of my interview. I will test different algorithms and directions for different people. I will ask them to choose different languages for implementation and talk about the relevant knowledge of their respective technology stacks based on different positions.
If you meet one of the following conditions:
- There are more than 66 open source projects star on Github;
- Experience of working in a listed Internet company or industry unicorn;
- Bachelor’s degree in Computer or software and cet-4;
- Graduates or current students from 211 key universities;
Just scan my wechat and set up an interview with me.
In order to improve the efficiency of the interview, after adding wechat, please first introduce your name, college and major of graduation, graduation time, the reason for looking for a job, etc., the students can refer to JS interview gem book to prepare.