Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  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. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement