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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:07:31+00:00 2026-05-30T20:07:31+00:00

I am writing a javascript based filter: There a lots of divs with the

  • 0

I am writing a javascript based filter:

There a lots of divs with the class .single that contain multiple text elements. The filter already hides all .single‘s that do not contain words:

//take them off dom, manip and put them back
singles.detach().each(function(i) {
    var $this = $(this);

    //make sure everything is visible
    $this.show();

    //if this template is not included OR if this index number does not meet the treshold
    if($.inArray(i, included) == -1 || treshold >= templates[i].score) {
        $this.hide();
    }
}).appendTo(container);

The array included contains all indexes of .single‘s that contain atleast one word. The array templates contains objects with all the text per .single and a score based on relevance and number of words. For example:

templates = [
    { text: ['long string', 'long string 2'], score: 5 },
    { text: ['sf sd', 'gdasd'], score: 3 }
]

(So all indexing doesn’t happen in the DOM)

Now what I want is to sort the set based on this score, or in other words: the highest score on the top. The index of each element in the set is the same as the index in templates (which contains all scores).

  • 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-30T20:07:33+00:00Added an answer on May 30, 2026 at 8:07 pm

    If you add the score to elements as data() in your $.each

    $(this).data('score', templates[i].score);
    

    You could then use the scores to sort

    function scoreSort(a, b) {
        return $(a).data('score') > $(b).data('score') ?1 :-1;
    
    }
    
    singles.sort( scoreSort);
    
    /* now replace html*/
    
    container.append( singles);
    

    I may be missing something, you say you want them in index order of templates but they must already be in that order for you to look at scores in templates using index in $.each

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

Sidebar

Related Questions

I'm writing a JavaSCript class that has a method that recursively calls itself. Scheduler.prototype.updateTimer
One thing I don't like about writing javascript-based applications is that you have to
I am writing a rather large JavaScript based application and sometimes there are cases
I would like to prepare a javascript-based system that would deselect the text after
In writing javascript based apps, I'm often finding that I want to include information
I'm writing a javascript based photo gallery with a horizontally scrollable thumbnail bar. >>
So I'm writing a Javascript library that takes x,y coordinates and uses them to
I'm writing some Javascript code that generates an XML document in the client (via
I'm writing a Javascript function that would manipulate an array written on-the-fly and sent
I'm writing a Java Webapp based on the Google Maps Javascript 3.0 API. I'm

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.