SHARE
TWEET

Untitled

a guest May 22nd, 2019 118 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. console.log( check_number( 8 ) );
  2.  
  3. function check_number( input ){
  4.     find_divisor( input ).map(e=>{
  5.         input -= e;
  6.     });
  7.  
  8.     if( input == 0 ){
  9.         return "완전수";
  10.     }else if( input > 0 ){
  11.         return "부족수";
  12.     }else if( input < 0 ){
  13.         return "초과수";
  14.     }
  15. };
  16.  
  17. function find_divisor( intput_value , target = 2 ){
  18.     if( intput_value % target == 0 ){
  19.         // 약수다.
  20.         if( intput_value == target ){
  21.             // 마지막일 경우
  22.             return [ 1 , intput_value ];
  23.         }else{
  24.             // 마지막이 아닐 경우
  25.             return find_divisor( intput_value / target , target + 1 ).concat( [ target ]);
  26.         }
  27.     }else{
  28.         // 약수가 아니다.
  29.         return find_divisor( intput_value , target + 1 );
  30.     }
  31. };
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