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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:50:12+00:00 2026-05-16T07:50:12+00:00

Please forgive me, but I do know js basics and how to write/call a

  • 0

Please forgive me, but I do know js basics and how to write/call a basic function, but in this case I’m trying to match an alpha sorted list of categories from the DB to match against my set (non-alpha) order of said categories as specified below (this is code suggested for use by another user on a question I asked about how to map the order of categories being returned). However, I can’t figure out how to integrate that person’s code answer into my own code.

Just seeing it implemented against another example list (to mimic what I would grab from the DB) and how I would call it in a switch case statement to wrap my html around the category names and return them to the web page in the mapped order I want would help a great deal. Sorry if it turns out to be obvious. I’m trying to learn what I can as I encounter these problems. Thanks!

var categories = [ 'F', 'C', 'A1', 'A2', 'A3' ].map(function (category) {
    return businesses.filter(function (business) {
        return business.category === category;
    });
});
  • 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-16T07:50:13+00:00Added an answer on May 16, 2026 at 7:50 am

    The code given looks most likely to be using the jQuery JavaScript library that has some useful functions such as map() for manipulating arrays.

    The code assumes that you have a jQuery object / array, businesses that contains the businesses that you need to order. If we read it from the outside in

    1. pass each item in the array in turn into the map function. The map function takes a function to say how each item should be mapped.
    2. The anonymous function function (category)... accepts one argument, the particular item passed to it in this iteration and will return the mapping result.
    3. the result returned is a function of calling filter on businesses and passing it a function to say how businesses should be filtered.
    4. The anonymous function function (business)... accepts an argument, the particular item passed to it as businesses is iterated and returns those that match the category argument scoped in the outer function.
    5. The end result is an array of items ordered by the category array [ 'F', 'C', 'A1', 'A2', 'A3' ]

    If we go back to the original problem, you need to order a list of categories based on the client’s preference. Let’s create a an object literal to map the ordering

    var map = {
        F : 5,
        C : 3,
        A1 : 1,
        A2 : 4,
        A3 : 2
    }
    

    We can use this map to order the array using the sort method

    var array = ['F', 'C', 'A1', 'A2', 'A3'];
    
    array.sort(function(a,b) {
        return map[a] - map[b];
    });
    

    This returns us ["A1", "A3", "C", "A2", "F"]

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

Sidebar

Related Questions

Please forgive my programming knowledge. I know this is a simple thing, but I
Please forgive the awkwardness of this question, I honestly don't know how to phrase
OK, I know that this has been asked previously, so please forgive me for
I'm new to jquery and asp.net so please forgive if this is an obvious
I'm a very novice OCaml programmer so please forgive me if this is a
Please bear with me, I'm just learning C++. I'm trying to write my header
I know this isn't a good thing to do, but its also a temporary
first off I am a rookie so please forgive my basic question. I am
Please forgive me if this question is ridiculous. I'm relatively new to programming and
I haven't really done much on this side of project development so please forgive

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.