const lexicographicCompare = (a, b) => {
const preparedA = a.trim();
const preparedB = b.trim();
const count = Math.max(preparedA.length, preparedB.length);
let index = 0;
for (let index = 0; index < count; index++) {
const diff = (preparedA.charCodeAt(index) || 0) - (preparedB.charCodeAt(index) || 0);
if (diff !== 0) {
return Math.sign(diff);
}
}
return 0;
};
const result = lexicographicCompare('111', '123');
if (result > 0) {
console.log('Second earlier');
} else if (result < 0) {
console.log('First earlier');
} else {
console.log('Equals');
}