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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:49:42+00:00 2026-06-03T23:49:42+00:00

Starting from an array of arbitrary values I would like to be able to

  • 0

Starting from an array of arbitrary values I would like to be able to extract all sequences of a given value.
So if I started with this

[1,0,1,1,1,1,0,0]

and searched for 1. I would like to get back

[[1],[1,1,1,1]]

I have seen an implementation in AS though not clear enough for me to translate over: finding sequences in AS3 array

  • 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-03T23:49:44+00:00Added an answer on June 3, 2026 at 11:49 pm

    I wrote one from scratch with code comments:

    function makeSequence(input, val) {
        var output = [], current = [];
    
        for (var i = 0; i < input.length; i++) {
            if (input[i] === val) {
                // if we have a matching value, add it to
                // the current match
                current.push(val);
            } else if (current.length) {
                // no match on current value, write out
                // any previous match
                output.push(current);
                current = [];
            }
        }
        // when done, make sure to add the last match
        if (current.length) {
            output.push(current);
        }
        return(output);
    }
    

    Working demo here: http://jsfiddle.net/jfriend00/YvsET/

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

Sidebar

Related Questions

Starting from this official statement that all xyAndroid versions previous API 11 doesn't support
How can I copy an array of values to a destination array starting from
Starting from scratch is hard. How do you do it? I quite like color
Starting from Android 3.2 I have this strange problem. It's very easy to reproduce:
I'm trying to figure out how to get a string from an array starting
i have this problem: starting from an empty list (0 elements) i want check
I would like to sort an array of strings (in JavaScript) such that groups
A have the string array and I need to select 9 elements starting from
i have a javascript array like this: array = [ {Command: SetDuration,QuestionId: 2,NewDuration: 1},
My char array would be looking something like below, Org_arr[1first line text------2second line text----3third

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.