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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:18:35+00:00 2026-05-28T18:18:35+00:00

Ideally, I’d like a solution in Ruby or Javascript. Arrays instead of ranges in

  • 0

Ideally, I’d like a solution in Ruby or Javascript. Arrays instead of ranges in javascript would be fine.

I’d like input such as:

    [0..301, 230..268, 242..364, 574..579, 587..593]

or

    [0,301, 230,268, 242,364, 574,579, 587,593]

And turn it into something like:

    [0..230, 230..242, 242..268, 268..301, 301..364, 574..579, 587..593]

or

    [[0,230], [230,242, [242,268], [268,301], [301,364], [574,579, [587,593]]

Any help would be great. This sort of helps but not fully because it gives the full range instead of the chunked ranges, How do I summarize array of integers as an array of ranges?.

  • 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-28T18:18:36+00:00Added an answer on May 28, 2026 at 6:18 pm

    Here’s a ruby solution:

    ranges = [0..301, 230..268, 242..364, 574..579, 587..593]
    endpoints = ranges.map{|r| [r.first, r.last]}.flatten.sort
    values = ranges.map{|r| r.to_a}.reduce(:+)
    
    new_ranges = []
    endpoints.reduce do |x, y|
        r = Range.new(x,y);
        new_ranges << r if r.all?{|v| values.include? v}
        y
    end
    
    puts new_ranges
    
    #0..230
    #230..242
    #242..268
    #268..301
    #301..364
    #574..579
    #587..593
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ideally I would like to do this using javascript client side scripting only. If
Ideally I would like a cross browser solution. Thanks!
Ideally I would like to be able to make the event target all p.hiddeninput,
Ideally I would like to have something similar to the Stopwatch class but with
I would ideally like to be able to add (very repetitive) C/C++ code to
I am seeking advice: Ideally, I would like to give an Administrator (of the
Ideally I would like to monitor the signal strength of a wireless network in
Ideally, where would an application like Facebook store its Friends data? In a database
I have created an NSImage object, and ideally would like to determine how many
Ideally I would like to do something like this.... $formElement->addValidator ( (new RegexValidator('/[a-z]/') )->setErrorMessage('Error')

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.