Advertisement
galink

Untitled

Aug 4th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function devide(args){
  2.  
  3. let n = Number(args[0]);
  4.  
  5. let p1 = 0;
  6. let p2 = 0;
  7. let p3 = 0;
  8.  
  9. for (let i = 1; i <= n; i++) {
  10.     let currentNum = Number(args[i]);
  11.     if(currentNum % 2 == 0) {
  12.         p1++;
  13.        
  14.  
  15.      
  16.     } else if(currentNum % 3 == 0) {
  17.         p2++;
  18.      
  19.        
  20.     } else  if(currentNum % 4 == 0) {
  21.         p3++;
  22.      
  23.     }
  24.  
  25.    
  26.  
  27. }
  28.    console.log((p1 / n * 100).toFixed(2) + '%');
  29.    console.log((p2 / n * 100).toFixed(2) + '%');
  30.    console.log((p3 / n * 100).toFixed(2) + '%');
  31. }
  32.  
  33.  
  34.  
  35. devide(['10', '680', '2', '600', '200', '800', '799', '199', '46','128','65']);
  36.  
  37. devide(['3','3','6','9']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement