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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:30:50+00:00 2026-06-07T22:30:50+00:00

I have an array called newposts I itterate through it and if it meets

  • 0

I have an array called newposts

I itterate through it and if it meets certain criteria, I add it to another array:

for (newpost in newposts){
    if (!(  newposts[newpost][0] in currentposts )){
        var triploc1 = locations[newposts[newpost][1]].location;
        var triploc2 = locations[newposts[newpost][2]].location;
        var detour_distance = fourpoint_distance(newloc1, triploc1, triploc2, newloc2);
        if (worthwhile_detour(original_distance,detour_distance)){
            currentposts.push(posts[newposts[newpost][0]])
        }
    }
}

The second row, is intended to check for duplicates(newposts[newpost][0]) is an ID. When I wrote it I had forgotten that currentposts was an array. Obviously, this doesn’t work. I need currentposts to be an array, because just below i sort it. I could ofcourse convert it into an array once the selection is done. But I’m new to javascript and believe someone might know a better way to do this.

function sortposts(my_posts){
    my_posts.sort(function(a, b) {
        var acount = a.sortvar;
        var bcount = b.sortvar;
        return (bcount-acount);
    });

}
  • 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-07T22:30:51+00:00Added an answer on June 7, 2026 at 10:30 pm

    I’m not exactly sure what your desired goal here is, but I can try and clean this up for you. Please note that I’m using the underscore.js library as it makes working with arrays a HECK OF A LOT easier 🙂 If you can’t include underscore.js into your project, let me know and I’ll write it in “pure” javascript 🙂

    _.each(newposts, function(item) {
        if ( _.indexOf(currentposts, posts[item[0]]) >= 0 ) {
            var triploc1 = locations[item[1]].location;
            var triploc2 = locations[item[2]].location;
    
            var detour_distance = fourpoint_distance(newloc1, triploc1, triploc2, newloc2);
    
            if (worthwhile_detour(original_distance, detour_distance)){
                currentposts.push(posts[item[0]])
            }
        }
    });
    
    _.sortBy(currentposts, function(item) {
        return item.sortvar;
    });
    

    I have to question, however, why you’re using so many arrays (newposts, locations, posts, etc)? Are they all needed?

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

Sidebar

Related Questions

I have an array called tmp var tmp = [05, 13, 27]; if an
I have an array called as wcs declared using var wcs= new Array(); .
I have an array called prices and another called orderT I want to check
I have an array called gallery_list: var gallery_list = [profile.cfm, explore.cfm, list.cfm, lesson.cfm, class.cfm,
Assume filteredArray={ 0,2,3,4}. I have another array called tempArray. I want to insert 1
My problem is: I have an array called $ownerArray that another array need to
I have an array called: $fragment = array($fragment); Which has the following three values:
I have an array called $times . It is a list of small numbers
I have a pretty simple problem. Basically I have an array called $list that
I have a large array called data. At the 10th array position i have

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.