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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:40:46+00:00 2026-06-09T01:40:46+00:00

I’m have beginner skills and am hoping someone can help me with a complex

  • 0

I’m have beginner skills and am hoping someone can help me with a complex script in JavaScript ECMA-262 (as basic a JS script as possible, since the program I am using has only older implementation of ECMA-262. So some some array functions like “splice” even “concat” are not found in the language reference for this program. But basic JS works OK).

I am trying to create an array totaling 6 numbers from 2 separate subarrays (subarrayA=1,2,3 and subarrayB=4,5,6), alternately placing a number (chosen randomly from each subarray) from each subarray into the final 6 item array. Also, no duplicates.

So, for example, 3,6,1,4,2,5.

I’ve tried online searching, this board, trying out zipper methods from 2 subarrays, % to pick out odd/even, etc. So far, nothing has worked. But at least I’ve gotten some more knowledge allowing me to ask the question in a way that may help create a more specific solution. I would hard code this, but I think that the number of possible variations/cases may be quite large?

I am hoping someone can suggest a script/function in basic JS that can (1) set up each random subarray, then (2) create the final 6 item array.

Kind Regards,

  • 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-09T01:40:48+00:00Added an answer on June 9, 2026 at 1:40 am

    If you’re restricted to a sub-set of the modern JS API, I would probably take the approach of first merging the two arrays (iteratively) then applying a random sort. Something like:

    var arr1 = [1,2,3], arr2 = [4,5,6];
    for (var i=0, len = arr2.length; i<len; i++) arr1[arr1.length] = arr2[i];
    arr1.sort(function() { return 0.5 - Math.random(); });
    

    arr1 is now an array of the 6 numbers in random order, no repeats.

    [EDIT] – based on the discussion below, try this.

    //prep - two arrays, randomised order
    var arr1 = [1,2,3].sort(r_sort),
        arr2 = [4,5,6].sort(r_sort),
        final_arr = [],
        smallest_array = arr1.length < arr2.length ? arr1 : arr2;
    function r_sort() { return 0.5 - Math.random(); }
    
    //build final array - intersecting the two arrays
    for (var i=0, len = smallest_array.length; i<len; i++) {
        final_arr[final_arr.length] = smallest_array[i];
        if (smallest_array == arr1 && arr2[i])
            final_arr[final_arr.length] = arr2[i];
        else if (smallest_array == arr2 && arr1[i])
            final_arr[final_arr.length] = arr1[i];
    
    }
    
    //result
    alert(final_arr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have an autohotkey script which looks up a word in a bilingual dictionary
I have a text area in my form which accepts all possible characters from
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.