Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Javascript prime number check

// 6k+-1 optimisation
function is_prime (n) {
  if (n < 3) return n > 1;
  else if (n % 2 === 0 || n % 3 === 0) return false;
  else if (n < 25) return true;
  let i = 5;
  while (i * i <= n ) {
    if (n % i === 0 || n % (i + 2) === 0) return false;
    i += 6;
  }
  return true;
}
Comment

javascript prime number checker program

function prime_checker(num){
    let is_prime;
    if (num===1){is_prime = false}
    else if (num===2||num===3){is_prime = true}
    else if (num%2===0){is_prime = false}
    else{
        let x = Math.floor(num/2);
        while (x>1){
            if (num%x===0){
                is_prime = false;
                break;
            }
            x = x-1;
            is_prime = true;
        }
    }
    
    return is_prime
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery get selected text from multiselect 
Javascript :: document selector query change value 
Javascript :: xml to json api in asp.net 
Javascript :: create subcollection firestore 
Javascript :: remove space from string javascript 
Javascript :: datatable destroy 
Javascript :: flutter text with icon 
Javascript :: check if string is valid date 
Javascript :: getelementbyxpath 
Javascript :: js make value positive 
Javascript :: drupal 8 get node from path alias 
Javascript :: filter falsy values js 
Javascript :: navigation reset 
Javascript :: checkbox on click jquery 
Javascript :: jquery source disable right click 
Javascript :: javascript select all divs with class 
Javascript :: write json file nodejs 
Javascript :: check if item exists in localstorage javascript 
Javascript :: last position of array javascript 
Javascript :: javascript get last item in array 
Javascript :: use local storage on server with node 
Javascript :: set stroke color canvas 
Javascript :: seleccionar value select2 js 
Javascript :: js check if date is future 
Javascript :: style before javascript 
Javascript :: mongodb filter empty array 
Javascript :: javascript paragraph count 
Javascript :: how to check if a message has an attachment discord js 
Javascript :: export variables react 
Javascript :: js after 1 second 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =