Skip to content

Instantly share code, notes, and snippets.

@Radvylf
Created May 3, 2022 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Radvylf/ef51b338ec8148083275b32f00430fcd to your computer and use it in GitHub Desktop.
Save Radvylf/ef51b338ec8148083275b32f00430fcd to your computer and use it in GitHub Desktop.
var items_2 = [];
var weights_2 = [];
for (var i = items.length - 1; i > 0; i++) {
if (i == items.indexOf(items[i])) { // If not a duplicate
items_2.push(items[i]);
weights_2.push(weights[i]);
}
}
items = items_2; // items_2 now contains all unique items
weights = weights_2; // weights_2 now contains the weights of all unique items
// This will be O(n^2), with a more complicated system with Maps or Sets you could probably get O(nlogn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment