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

  • Home
  • SEARCH
  • 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 6809923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:08:37+00:00 2026-05-26T20:08:37+00:00

I want to write a function which removes elements from an array of integers

  • 0

I want to write a function which removes elements from an array of integers starting from the lowest values without changing the positions of the elements. Programming language is ActionScript3.

e.g. (these are individual trace statements)

    var aNumArr:Array = [0,7,2,5,9,0]
    trace(RemoveMinValues(aNumArr, 1, false)) //output: 7,2,5,9,0
    //trace(RemoveMinValues(aNumArr, -1, true)) //output: 0,7,2,5,9
    //trace(RemoveMinValues(aNumArr, 2)) //output: 7,2,5,9

I have managed to remove the lowest values in an array using sort(Array.NUMERIC) and sort(Array.DESCENDING).

But I can’t seem to figure out how to move the elements back to their original positions.

As this is an assignment, I cannot copy the entire function code. And I wish you not to tell me the exact answer, but rather give me insight on how to go about doing it.

Hope I was clear enough. Please let me know if you need additional info.

Thanks in advance.


EDIT: I realised I missed out a few things on the function. I’ve also changed the aNumArr and desired output values to make it clearer what I want.

And here was what I did previously:

    function RemoveMinValues(aNumArr:Array, iMinsToRemove:int):void
    {
         if(iMinsToRemove >= 0)
         {
              aNumArr.sort(Array.NUMERIC);
              for(var i:int = 0; i < iMinsToRemove; ++i)
              {
                   aNumArr.shift();
              }
         }
         else
         {
              aNumArr.sort(Array.DESCENDING);
              for(var i:int = 0; i > iMinsToRemove; --i)
              {
                   aNumArr.pop();
              }
         }
    }

Basically aNumArr:Arrayis the array of integers specified.
AndiNumbersOfMinsToRemove:int is the number of min values to remove.
The Assignment requires me to return nothing.

I know Array.NUMERIC and Array.DESCENDING would change the position of the elements, but I can’t seem to figure out the logic on how to keep their positions. Please try to keep as simple a possible. I’m still an ameture.

  • 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-26T20:08:38+00:00Added an answer on May 26, 2026 at 8:08 pm

    Instead of removing the value, set it to null. Better still, set it to Math.NEGATIVE_INFINITY so that the sorting order remains unchanged.

    That way, the array indices will remain the same because you are modifying the value, not removing it

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

Sidebar

Related Questions

I want to write a function which can validate a given value (passed as
I want to write a function that accepts a parameter which can be either
i want to write a function that prints multi-dimensional objects which are text (or
I want to write a function like equalp, which gives #t for (equalp Xy
I want to write a function in Python that returns different fixed values based
I want to write a function that takes an array of letters as an
i need to write a function which calculates how many elements on list with
I want to write a rename function to replace String names (which represent hierarchical
Let's say I want to have a function which reads data from the SerialPort
I want to write the following function which should be used in an Excel

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.