We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Ruby
  3. Arrays & Hashes
  4. Ruby Array - Initialization

Ruby Array - Initialization

Problem
Submissions
Leaderboard
Discussions

One of the most commonly used data structures in Ruby is a Ruby Array, and below we see various methods of initializing a ruby array.

Your task is to initialize three different variables as explained below.

  • Initialize an empty array with the variable name array

Hint

array = Array.new

or

array = []
  • Initialize an array with exactly one nil element in it with the variable name array_1

Hint

array_1 = Array.new(1)

or

array_1 = [nil]
  • Initialize an array with exactly two elements with value 10 in it using the variable name array_2.

Hint

array_2 = Array.new(2, 10)

or

array_2 = [10, 10]

Author

dheeraj

Difficulty

Easy

Max Score

10

Submitted By

22724

Need Help?


View discussions
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy