Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

319
Views
¿Cómo devolver todos los números pares dentro de una matriz dentro de un hash?

Me han dado la siguiente estructura de datos:

 users = { "Jonathan" => { :twitter => "tronathan", :favorite_numbers => [12, 42, 75], }, "Erik" => { :twitter => "sferik", :favorite_numbers => [8, 12, 24], }, "Anil" => { :twitter => "bridgpal", :favorite_numbers => [12, 14, 85], }, }

Necesito devolver todos los números favoritos de Anil que sean pares. Esto es lo que tengo hasta ahora:

 users["Anil"][:favorite_numbers].each do |evennum| if evennum.even? puts evennum end end
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Podrías hacer algo como esto

 anil_favorite_even_numbers = users['Anil'][:favorite_numbers].select(&:even?)

Esto da por sentado que existe un usuario Anil y los favourite_numbers dentro de él también y eso es una matriz. De lo contrario, necesitamos un poco de trabajo extra.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!