0

I'm stumbling on using a ternary with the p() function in ruby. My code is:

 p i.prime?? i:''

Problem is, when i is not prime, it displays quotes instead of displaying nothing.

How do I fix this and make it print nothing? I don't want to print whitespace either. just nothing.

Razetime
  • 216
  • 3
  • 19

1 Answers1

1

Check the difference between p and puts here: p vs puts in Ruby

For your question, sticking with the ternary, try just:

i.prime? ? (p i) : ''
iGian
  • 11,023
  • 3
  • 21
  • 36