Advertisement
butumusho

multiples of 3 and 5

Aug 3rd, 2023
1,895
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.47 KB | None | 0 0
  1. def multiple_of_three?(number)
  2.     number % 3 == 0
  3. end
  4.  
  5. def multiple_of_five?(number)
  6.     number % 5 == 0
  7. end
  8.  
  9. def ping_pong_iterate(range)
  10.     range.each do |number|
  11.         word = word_or_number(number)
  12.         puts word
  13.     end
  14. end
  15.  
  16. def word_or_number(word = '', number)
  17.     word << 'APing' if multiple_of_three?(number)
  18.     word << 'BPong' if multiple_of_five?(number)
  19.    
  20.     word.empty? ? number : word
  21. end
  22.  
  23. range = (1..100)
  24. ping_pong_iterate(range)
Advertisement
Comments
  • aliahhmad044
    1 year
    # text 0.32 KB | 0 0
    1. SCAM, AFTER ADVISING ME TO MAKE A HUGE
    2. DEPOSIT, NOW NO ANSWER TO MY CALLS OR EMAILS
    3. ANYMORE, 8200$ GONE.. I SAW A REVIEW OF
    4. HOW TO GET HELP WITH OLIVIATRADER44 @ GMAIL. COM ON GOOGLE AND I GOT IN CONTACT WITH
    5. AND MY MONEY WAS RETRIEVED BACK TO
    6. ME. CONTACT THEM THROUGH THEIR WHATSAPP +1 (423) 248-2140 IF
    7. YOU NEED HELP TOO
Add Comment
Please, Sign In to add comment
Advertisement