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 8381719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:45:22+00:00 2026-06-09T16:45:22+00:00

I have an array of arrays indicating coordinate values, like so: cells = [

  • 0

I have an array of arrays indicating coordinate values, like so:

cells = [ [0,0], [0,1] ]

Each array in the array is an X and Y value. So, if I want to shift this right, that would be X+1 on each cell. I could express this as a cell like so:

delta = [1,0]

Now, what I’d like to do is merge that value into each cell so that the X value of each cell is summed with the value of delta, so in this case the final output should be:

new_cells = [ [1,0], [1,1] ]

Here’s the best I’ve been able to think of so far, it seems really heavy:

cells = [[0,0],[0,1]]
delta = [1,0]
cells.each do |cell|
  cell[0] = cell[0] + delta[0]
  cell[1] = cell[1] + delta[1]
end
# Now cells = [[1,0],[1,1]]

Is there a cleaner one-liner kind of method that would sum an array onto each array in a chain of arrays, or is the above the best solution to that problem?

  • 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-06-09T16:45:23+00:00Added an answer on June 9, 2026 at 4:45 pm

    I think your best solution is to recognize that cells and deltas are a different data type that you could operate on more clearly if it weren’t an array:

    Cell = Struct.new(:x, :y) do 
      def + other
        Cell.new(self.x + other.x, self.y + other.y)
      end
    end
    
    # cells is some array of Cell objects
    # delta is some Cell object
    
    cells.map! {|cell| cell + delta}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array ($configOptions) which contains some arrays. Each array ($option) in that
Let's say I have an array that looks like this: $array[0] = 'House'; $array[1]
I have an array that contains an array of arrays if that makes any
i have an array $mainArray of arrays and i would like to remove /
I have a multidimensional array of arrays (source below), where my keys and values
Let's say I have an array that has 4 arrays in it. What I
We have this field in our database indicating a true/false flag for each day
I have a method that starts like this: public static UnboundTag ResolveTag(Type bindingType, string
I have a div that can display 3 images (in the background) each indicating
I have an array like this Array['one','two','three','four','five'] and I have an array like this

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.