functionhigherVersion(version1,version2){// split the strings into numbersconstsplit1=version1.split('.').join('');constsplit2=version2.split('.').join('');returnNumber(split1)>Number(split2);}// TEST CASESconsttestInput01=["1.2.3","1.2.0"];// trueconsttestInput02=["9","10"];// false// OUTPUTconsole.log("--------------");console.log(higherVersion(testInput01[0],testInput01[1]));console.log(higherVersion(testInput02[0],testInput02[1]));console.log("----------------------------");
With the assumption that the two versions are the same length and have no leading zeros, yes. I'd probably recommend .replaceAll('.', '') over split('.').join('').
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
But this is faster and simpler right?
With the assumption that the two versions are the same length and have no leading zeros, yes. I'd probably recommend
.replaceAll('.', '')
oversplit('.').join('')
.