Skip to content

Instantly share code, notes, and snippets.

@betterkenly
Created August 3, 2017 16:59
Show Gist options
  • Save betterkenly/40919a176a91e91f3bbdb8d6e12a5a4e to your computer and use it in GitHub Desktop.
Save betterkenly/40919a176a91e91f3bbdb8d6e12a5a4e to your computer and use it in GitHub Desktop.
i tried
var maxEnvelopes = function(envelopes) {
var result = [];
var sorted0 = envelopes.sort((a,b) => {
return a[0] - b[0];
});
var sorted1 = envelopes.sort((a,b) => {
return a[1] - b[1];
});
for (var i = 0; i < sorted0.length; i++) {
if (compare(sorted0[i],sorted1[i])) {
result.push(sorted0[i]);
}
}
for(var j = 0; j < result.length - 1 ; j++) {
if (result[j][0] < result[j + 1][0] && result[j][1] < result[j + 1][1]) {
continue;
} else {
result.splice(j,1);
j++;
}
}
return result.length;
};
var compare = function(a,b) {
return a.every((each, i) => {
return each === b[i];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment