SHARE
TWEET

Untitled

a guest Feb 14th, 2020 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let from = document.querySelector('.from'),
  2.     to = document.querySelector('.to'),
  3.     trigger = document.querySelector('.trigger'),
  4.     result = document.querySelector('.response');
  5.  
  6.  
  7. function getBiggestPrime(from, to){
  8.   var divisors = [],
  9.       primes = [];
  10.       for(var i = from; i <= to; i++){
  11.           for(var j = 1; j <= i; j++){
  12.             if(Number.isInteger(i/j)){
  13.               divisors.push(j);
  14.             }
  15.           }
  16.         //alert(divisors);
  17.         if(divisors.length == 2){
  18.           primes.push(i);
  19.         }
  20.         divisors = [];
  21.       }
  22.   //alert(primes);
  23.   result.innerHTML = "Najwiekszą liczbą pierwszą zbioru "+from+"-"+to+" jest "+Math.max.apply(Math, primes);
  24.   primes = [];
  25. }
  26. trigger.addEventListener('click', function(ev){
  27.   getBiggestPrime(from.value,to.value);
  28. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top