In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the common algorithm questions in JS interview". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the common algorithm questions in JS interview"?
1. Verify whether a number is a prime
1. If the number is 2 or 3, it must be prime
2. If it is an even number, it must not be a prime
3. If this number is not divisible by 3mure-any of its square roots, m must be a prime. And the divisor can be incremented each time (excluding even numbers)
Function isPrime (num) {
If (num = 2 | | num = 3) {
Return true
}
If (num% 2 = = 0) {
Return false
}
Let divisor = 3 limit = Math.sqrt (num)
While (limit > = divisor) {
If (num% divisor = = 0) {
Return false
}
Else {
Divisor + = 2
}
}
Return true
}
Console.log (isPrime (30)); / / false
two。 Fibonacci
The simplest thing to do: recursion.
Function fibonacci (n) {
If (n = divisor) {
If (a%divisor = 0 & & b%divisor = = 0) {
Res = divisor
}
Divisor++
}
Return res
}
Console.log (greatestCommonDivisor (8,4)); / / 4
Console.log (greatestCommonDivisor (69,169); / / 1
Solution 2:
Function greatestCommonDivisor (a _ r _ b) {
If (b = 0) {
Return a
} else {
Return greatestCommonDivisor (bmaine a% b)
}
}
4. Array deduplication
Traverse the original array
Get the value j of arr [I]
The value corresponding to the position j of the auxiliary array exits. If not, it is proved that the value of arr [I] is not duplicated.
At this point, the value j is stored in the res array, and the value of the auxiliary array j position is set to true.
Finally, the res array is returned.
Thank you for your reading, the above is the content of "what are the common algorithm questions in JS interview". After the study of this article, I believe you have a deeper understanding of what are the common algorithm questions in JS interview, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.