in web/src/js/gcping.js [217:254]
function addResult(regionKey) {
if (!results.length) {
results.push(regionKey);
return;
}
// remove any current values with the same regionKey
for (let i = 0; i < results.length; i++) {
if (results[i] === regionKey) {
results.splice(i, 1);
break;
}
}
// TODO: Probably use Binary search here to merge the following 2 blocks
// if new region is at 0th position
if (compareTwoRegions(regionKey, results[0]) < 0) {
results.unshift(regionKey);
return;
}
// if new region is at last position
else if (compareTwoRegions(regionKey, results[results.length - 1]) > 0) {
results.push(regionKey);
return;
}
// add the region to it's proper position
for (let i = 0; i < results.length - 1; i++) {
// if the region to be added is b/w i and i+1 elements
if (
compareTwoRegions(regionKey, results[i]) >= 0 &&
compareTwoRegions(regionKey, results[i + 1]) < 0
) {
results.splice(i + 1, 0, regionKey);
return;
}
}
}