FAQ: The Refactor Factory - Nice work!

This community-built FAQ covers the “Nice work!” exercise from the lesson “The Refactor Factory”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Ruby

FAQs on the exercise Nice work!

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Why did this return an array? I was expecting it to return the first 10 primes (which it did) but I did not expect them to be bracketted! :
require ‘prime’
def first_n_primes(n)
return “n must be an integer.” unless n.is_a? Integer
return “n must be greater than 0.” unless n > 0
Prime.first n
end

puts first_n_primes(10)

From the Ruby docs for Prime at Class: Prime (Ruby 2.5.1) , you’ll see that Prime is enumerable, the set of all the prime numbers, which you can use array methods on, so you choose the first n using .first Class: Array (Ruby 2.4.1)

1 Like