Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6736247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:06:27+00:00 2026-05-26T11:06:27+00:00

I have a large array, h , that contains several instances of a parameter

  • 0

I have a large array, h, that contains several instances of a parameter called startingParam, which is always followed by two other parameters that are related but not always the same. I need to look for every instance of startingParam in the array, and push it and the next two parameters into a separate array, holdingArray.

The following code is not working, due to the fact that I am very new to Ruby. Does anybody know what I am doing wrong? Is there a better way to approach the problem?

h.each do |param|
    if param == 'startingParam'
        holdingArray << h.[param],
        holdingArray << h.[param + 1],
        holdingArray << h.[param + 2]
    end
end

Thanks so much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:06:27+00:00Added an answer on May 26, 2026 at 11:06 am

    So there are a few problems. For starters, you can’t subscript arrays by doing h.[anything], and you are also subscripting based on the value (and not the index). You are also checking to see if the parameter matches the literal string “starting_param” and not its value. So what I expect you want is the following:

    h.each_with_index do |param, index|
      if param == startingParam
        holdingArray << h[index]
        holdingArray << h[index+1]
        holdingArray << h[index+2]
      end
    end
    

    You’ll also note that if the item is in the last two slots of the array, this will wrap around and grab items from the beginning of the array (due to how Ruby handles array subscripts being out of bounds).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large array in PHP. It contains strings that are split into
I have a large 2d array that I serialize and base64_encode and throw into
So I have a large 2d array that i serialize, but when I attempt
I have a large array in C (not C++ if that makes a difference).
I have two arrays, one is very large (more than million entries) and other
I have a rather large list of data that contains 5 properties per element.
I have a large array of vertices, some of them are edges, some are
Imagine you have a large array of floating point numbers, of all kinds of
I have a large int[] array and a much smaller int[] array. I want
Hey. I have a very large array and I want to find the Nth

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.