Skip to content

Instantly share code, notes, and snippets.

@see-why
Created March 20, 2022 22:06
Show Gist options
  • Save see-why/ccf8fc7cf09db87fa91ef40efab05e20 to your computer and use it in GitHub Desktop.
Save see-why/ccf8fc7cf09db87fa91ef40efab05e20 to your computer and use it in GitHub Desktop.
HackerRank The Love Letter Mystery challenge solution
// https://www.hackerrank.com/challenges/the-love-letter-mystery/problem?isFullScreen=true
function theLoveLetterMystery(s) {
// Write your code here
let operations = 0;
for (let i=0; i<s.length/2; i++){
let char = s.charCodeAt(i)
let alternate = s.charCodeAt(s.length - (1 + i))
if(char != alternate) {
operations+= Math.abs(char-alternate)
}
}
return operations;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment