Created
December 1, 2020 15:06
-
-
Save cziem/23eeddfa669c7d5aee6ad96e06d875d9 to your computer and use it in GitHub Desktop.
Return only sorted large pairs
This file contains hidden or 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
// 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