Skip to content

Instantly share code, notes, and snippets.

@cziem
Created December 1, 2020 15:06
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 cziem/23eeddfa669c7d5aee6ad96e06d875d9 to your computer and use it in GitHub Desktop.
Save cziem/23eeddfa669c7d5aee6ad96e06d875d9 to your computer and use it in GitHub Desktop.
Return only sorted large pairs
// inputData = 64,120
// 63,121
// 65,100
// 70,150
// 56,90
// 75,190
// 60,95
// 68,110
function writeOutput(inputData) {
// Start writing code here to consume input, and return result.
// Remove newline characters from the inputData
let inputArr = inputData.split("\n");
let numArr = [];
// Convert the inputData into an array of numbers for easier comparison
for (let value of inputArr) {
let subValueSplits = value.split(",");
numArr.push([parseInt(subValueSplits[0]), parseInt(subValueSplits[1])]);
}
let local = numArr.sort((a, b) => {
return a[0] - b[0] && a[1] - b[1];
});
let oddValues = [];
local.sort((a, b) => {
if (a[0] < b[0]) {
oddValues.push(a);
}
});
let res = [];
for (let pair of local) {
if (!oddValues.includes(pair)) {
res.push(pair);
}
}
return res.map((item) => item.toString() + "\n").join("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment