Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

hwo to make ana array of prime numbers in javascript

function sort_prime(num) {

  var prime_num1 = [],
      prime_num2 = [];
  for (var i = 0; i <= num; i++) {
    prime_num2.push(true);
  }
  for (var i = 2; i <= num; i++) {
    if (prime_num2[i]) {
      prime_num1.push(i);
      for (var j = 1; i * j <= num; j++) {
        prime_num2[i * j] = false;
      }
    }
  }

  return prime_num1;
}

console.log(sort_prime(5))
Comment

PREVIOUS NEXT
Code Example
Javascript :: js script 
Javascript :: jquery is not defined rails 
Javascript :: on() jquery 
Javascript :: javascript join object properties in array 
Javascript :: csv to json python 
Javascript :: how to make a game in unity with javascript 
Javascript :: javascript convert object to querystring 
Javascript :: anime js link 
Javascript :: how to change background color though props 
Javascript :: delete node module 
Javascript :: suspense react 
Javascript :: how to find the last word of a string in javascript 
Javascript :: javascript object to query string 
Javascript :: column width table react 
Javascript :: javascript inject html 
Javascript :: what is startof() in moment 
Javascript :: ok that is something 
Javascript :: javascript stop execution 
Javascript :: short ajax get method jquery 
Javascript :: vue js import css from node modules 
Javascript :: delete a node in dom javascript 
Javascript :: js tolowercase 
Javascript :: ctx.fillstyle 
Javascript :: javascript dynamic arrays 
Javascript :: CREATE A BUTTON THAT INCREMENTS A COUNTER WHEN CLICKED 
Javascript :: react read multiple files with filereader 
Javascript :: javascript remove duplicates 
Javascript :: javascript onkeydown 
Javascript :: javascript Swapping Variables 
Javascript :: angular jspdf 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =