+ 1
Can someone explain me this code?
I got a code from internet for calculating prime numbers and i like to know how is it working I dont have problem to line 15 of javascript Can someone explain me other lines of js pls? https://code.sololearn.com/W5TPnrdP6n7D/?ref=app
3 Answers
+ 1
https://code.sololearn.com/WCgYLZ9YtfHO/?ref=app
I have added comments to the code. I hope you get it..
P.S. i found that the code didn't print 2 which is a prime number and it printed 1 which is neither a prime nor a composite number
https://www.quora.com/Why-is-1-neither-prime-nor-composite#:~:text=A%20natural%20number%20(i.e.%201%2C%202%2C%203%2C%204,one%20positive%20factor%20i.e.%20no.&text=Hence%201%20is%20neither%20prime%20nor%20composite.,-It%20forms%20its
So i think it would be quite wrong to use it..i created this thing in a easier way.. Try it
https://code.sololearn.com/WETiK48aUtJ1/?ref=app
+ 1
Here are some resources about the methods that the code uses:
IIFE
https://stackoverflow.com/questions/8228281/what-is-the-function-construct-in-javascript
Array.reduce
https://www.w3schools.com/jsref/jsref_reduce.asp#:~:text=The%20reduce()%20method%20reduces,for%20array%20elements%20without%20values.
addEventListener
https://www.w3schools.com/jsref/met_element_addeventlistener.asp
+ 1
Very thx