SHARE
TWEET

Untitled

Gancho69 Feb 22nd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.  
  3.     let num = input.shift();
  4.     let primeSum = 0;
  5.     let nonPrimeSum = 0;
  6.  
  7.     while (num !== "stop") {
  8.         num = +(num);
  9.         let prime = true;
  10.         if (num === 1) {
  11.             prime = false;
  12.         }
  13.         if (num < 0) {
  14.             console.log(`Number is negative.`);
  15.             num = input.shift();
  16.             continue;
  17.         }
  18.         // prowerka da si ebe mamata ama oshte ne sym q izmislil
  19.         for (let i = 2; i <= num; i++) {
  20.             if (num % i === 0 && i !== num) {
  21.                 prime = false;
  22.             }
  23.  
  24.         }
  25.         //i tuka si prodyljava moje bi
  26.         if (prime) {
  27.             primeSum += num
  28.         } else {
  29.             nonPrimeSum += num;
  30.         }
  31.         num = input.shift();
  32.     }
  33.     console.log(`Sum of all prime numbers is: ${primeSum}`);
  34.     console.log(`Sum of all non prime numbers is: ${nonPrimeSum}`);
  35. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top