Tell me how would you empty the array below?
Submitted by: MuhammadVar emptyArray = [‘this', ‘array', ‘is', ‘full'];
This deceptively simple question is designed to test your prospective coder's awareness of mitigating potential bugs when solving problems. The easiest method would be to set “emptyArray” equal to “[ ]”-which creates a new empty array. However, if the array is referenced anywhere else, the original array will remain unchanged. A more robust method would be “emptyArray.length – 0;”-which not only clears the array but updates all reference variables that point to this original array. Some possible solutions are listed below:
emptyArray.length = 0;
emptyArray.splice(0, emptyArray.length);
while(emptyArray.length){
emptyArray.pop();
}
emptyArray = []
Submitted by: Muhammad
This deceptively simple question is designed to test your prospective coder's awareness of mitigating potential bugs when solving problems. The easiest method would be to set “emptyArray” equal to “[ ]”-which creates a new empty array. However, if the array is referenced anywhere else, the original array will remain unchanged. A more robust method would be “emptyArray.length – 0;”-which not only clears the array but updates all reference variables that point to this original array. Some possible solutions are listed below:
emptyArray.length = 0;
emptyArray.splice(0, emptyArray.length);
while(emptyArray.length){
emptyArray.pop();
}
emptyArray = []
Submitted by: Muhammad
Read Online Full-Stack Developer Job Interview Questions And Answers
Top Full-Stack Developer Questions
☺ | Explain me what are the disadvantages of using JavaScript? |
☺ | Explain me which frameworks are you most familiar with? |
☺ | Can you write a function that can determine whether a string is a palindrome in under 100 characters? |
☺ | Tell us are you a team player? Give an example of a time when you had to resolve a conflict with another member on your team? |
☺ | Can you tell me what is starvation? |
Top Coding/Programming Categories
☺ | Python Interview Questions. |
☺ | OOP Interview Questions. |
☺ | Software engineering Interview Questions. |
☺ | PHP Interview Questions. |
☺ | VBA (Visual Basic for Applications) Interview Questions. |