-
-
Save Radvylf/ef51b338ec8148083275b32f00430fcd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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