Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const more = (item1, item2) => {
- if (item1[0] > item2[0]) {
- return true;
- } else if (item1[0] == item2[0]) {
- if (item1[1] > item2[1]) {
- return true;
- }
- return false;
- }
- };
- const sorter = (arr) => {
- for (let i = 0; i < arr.length; i++) {
- for (let j = 0; j < arr.length - i - 1; j++) {
- if (more(arr[j], arr[j + 1])) {
- const buf = arr[j + 1];
- arr[j + 1] = arr[j];
- arr[j] = buf;
- }
- }
- }
- return arr;
- };
- const arr1 = [
- [3, 1],
- [1, 2],
- [1, 3],
- [2, 2],
- [2, 1],
- [3, 2],
- [2, 2],
- [1, -1]
- ];
- console.log(sorter(arr1));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement