Advertisement
gtoroap

Untitled

Jan 9th, 2023
1,241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.32 KB | None | 0 0
  1. def ping_pong(n)
  2.   values = []
  3.   (1..n).each do |num|
  4.     ping = (num % 3 == 0)
  5.     pong = (num % 5 == 0)
  6.     if ping && pong
  7.       values << 'APingBPong'
  8.     elsif ping
  9.       values << 'APing'
  10.     elsif pong
  11.       values << 'BPong'
  12.     else
  13.       values << num
  14.     end
  15.   end
  16.   values
  17. end
  18.  
  19. print ping_pong(100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement