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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:18:48+00:00 2026-06-09T22:18:48+00:00

[I apologize in advance for the complexity of the problem… but what good problem

  • 0

[I apologize in advance for the complexity of the problem… but what good problem is simple?]

I manage the on-call roster for a largish (22 member) production support team. the list is a “full escalation” (all team members are listed) and generated monthly. Since those near the top of the list are called into overnight issues (and tend to be unavailable) we leverage the list in reverse to create our daytime assignment roster.

The Problem

After an unreasonable amount of time, politics and argument (don’t ask) a rather silly rule set was created and agreed upon to generate this roster. To generate the daily assignment roster:

“Going backwards up the on-call list select the “even” ranks on the list and place them first in descending order. Then do the same thing for the “odds” placing them on the roster.”

So, a simple example:

On-call: “1-Jack, 2-Jim, 3-Jane, 4-John, 5-Jill, 6-Joe”
Roster: “1-Joe, 2-John, 3-Jim, 4-Jill, 3-Jane, 1-Jack”

The primary wrinkle is that, due to vacation, PTO, other assignments, etc time the on-call list is sparse (there may be empty slots). So a more real-world example might be:

On-call: “1-Jack, 3-Jane, 4-John, 6-Joe”
Roster: “1-Joe, 2-John, 3-Jane, 4-Jack

The real list is 22 people. On any given given day we average about 17 or 18 available. The missing people don’t impact the on-call – you just keep moving to the next highest – but they are making working within the roster rules painful.

The Current (Inelegant) Solution

Currently I have this working brute-force style. I first create an array of objects representing the on-call where each object has the name and on-call rank of a person. (It did just occur to me that I could probably simplify this by creating a sparse array of just the names where the index represented the actual rank… but I don’t think it changes the issue).

I then loop through the array twice from last-to-first: first to collect the even ranks (by getting the modulus of the Rank) and push them onto a new array, second to collect the odds:

                       // Get the Current Oncall 
           var Oncall = new Array(); 
           for ( var iCnt = 1; iCnt <= 22; iCnt++ ) { 
                   var CurOncall = DataRows[Cnt].getAttribute("ows_OnCall" + iCnt); 
                   if ( CurOncall != null ) { 
                           Oncall[Oncall.length] =  {"Name":CurOncall, "Rank": iCnt}; 
                   }; 
           }; 
                   // Get the Current Roster 
           var Roster = new Array(); 
                   // Add the "evens" 
           for ( var iCnt = Oncall.length - 1; iCnt >= 0; iCnt-- ) { 
                           // Get the Current Incident Rank 
                   if ( Oncall[iCnt].Rank % 2 == 0 ) { 
                           Roster[Roster.length] = Oncall[iCnt].Name; 
                   }; 
           } 
                   // Add the "odds" 
           for ( var iCnt = Oncall.length - 1; iCnt >= 0; iCnt-- ) { 
                           // Get the Current Incident Rank 
                   if ( Oncall[iCnt].Rank % 2 != 0 ) { 
                           Roster[Roster.length] = Oncall[iCnt].Name; 
                   }; 
           } 

Note that this snippet exists within a larger loop (I’m looping over a week’s worth of data, this is only one day). DataRows[Cnt] is the current day’s information as pulled from a SharePoint web service.

Again, this works fine, but requires three loops over the same data for each day’s processing.

The Current (Broken) Solution

What I’d like to do is get to the poing where I can generate the Roster from the on-call using a single loop. Moving in that directly I’ve been working on just combining the second two loops into one. Assuming that the Oncall array is generated the same as above this is my current attempt (it’s a little ugly):

       var IncCnt = 1; 
   for ( var Cnt = OnCall.length - 1; Cnt >= 0; Cnt-- ) { 

                   // Get the Current Incident (Roster) Rank 
           if ( OnCall[Cnt].Rank % 2 == 0 ) { 
                   CurIncRank = Math.ceil(IncCnt / 2); 
           } else { 
                   CurIncRank = Math.ceil(IncCnt / 2) + Math.floor(OnCall.length / 2) 
           }; 

           Roster[CurIncRank] = OnCall[Cnt].Name;
                   // Increase the Incident Cnt
           IncCnt = IncCnt + 1; 

   }; 

This comes close to working, but tends to either overlap (overwriting the last “even” with the first “odd”) or leave a gap between the evens and odds depending the sparseness and total number of elements.

Conclusion

The primary goal is to generate the roster “on the fly” directly in the first loop rather than creating a specific on-call array then generating it from that – but currently I’d happy settle for getting just the second snippt to work in all cases.

I’m also open to the possibility that this may just not be able to work. Maybe the combination of an inelegant rule set and inelegant data simply require the brute-force method. If that’s the case I’d just prefer to hear it from better programmers than myself before giving up.

Thanks in advance. Feel free to ask for any clarifications.

  • 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-09T22:18:50+00:00Added an answer on June 9, 2026 at 10:18 pm

    So, if I read you correctly, you have an ‘onCall’ array of objects, each object containing a name and rank, like so:

    var onCall = [
        {
            rank: 1,
            name: 'Jack'
        },
        {
            rank: 3,
            name: 'Jill'
        },
        ...
    ];
    

    Then, you want to create a roster array that contains the evenly ranked people in descending order followed by the odd ranked people in descending order. If that’s correct, then the following code would produce such an array:

    for(var i = onCall.length-1; i >= 0; i--) {
        person = onCall[i];
        if(person.rank % 2 === 0) {
            evens.push(person);
        } else {
            odds.push(person);
        }
    }
    roster = evens.concat(odds);
    

    You go through the array once, in reverse. For each person, append them to either ‘evens’ or ‘odds’ depending on their rank. Finally, you simply concatenate the two arrays into a new ‘roster’ array.

    Here is a demo:

    — jsFiddle DEMO —

    I apologize that this isn’t written with your particular variable names, but if this is what you’re looking for, it should be easily changed to suit your environment.

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

Sidebar

Related Questions

I'm relatively new to scripting and apologize in advance for this painfully simple problem.
I apologize in advance because this is somehow a silly question, but I just
I apologize in advance if I am asking asking question with impossible answer. But
I apologize in advance for the open-ended question. I tried searching, but wasn't sure
I apologize in advance for the rambling nature of this question, but I have
I apologize in advance for this somewhat ignorant question, but I have researched this
I am going to apologize in advance for being extremely vague, but my knowledge
I apologize in advance for a newbie question, but why do I get Access
I apologize in advance if this is a newb question, but what are some
I apologize in advance if this has been asked before, but I haven't been

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.