という配列がありますnewposts
それを反復処理し、特定の基準を満たしている場合は、別の配列に追加します。
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]])
}
}
}
2 行目は、duplicates( newposts[newpost][0]
) が ID であることを確認するためのものです。私がそれを書いたとき、私は currentposts が配列であることを忘れていました。明らかに、これは機能しません。すぐ下にソートするため、現在の投稿を配列にする必要があります。もちろん、選択が完了したら、それを配列に変換できます。しかし、私はJavaScriptが初めてで、誰かがこれを行うためのより良い方法を知っていると信じています.
function sortposts(my_posts){
my_posts.sort(function(a, b) {
var acount = a.sortvar;
var bcount = b.sortvar;
return (bcount-acount);
});
}