What does .call mean ? (Question from Caesar's Cipher)

Was looking at the solution for Caesar’s Cipher (https://forum.freecodecamp.com/t/algorithm-caesars-cipher/16003)

The solution is:

function rot13(str) {
  // Split str into a character array
  return str.split('')
  // Iterate over each character in the array
    .map.call(str, function(char) {
      // Convert char to a character code
      x = char.charCodeAt(0);
      // Checks if character lies between A-Z
      if (x < 65 || x > 90) {
        return String.fromCharCode(x);  // Return un-converted character
      }
      //N = ASCII 78, if the character code is less than 78, shift forward 13 places
      else if (x < 78) {
        return String.fromCharCode(x + 13);
      }
      // Otherwise shift the character 13 places backward
      return String.fromCharCode(x - 13);
    }).join('');  // Rejoin the array into a string
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");

What exactly the does .call function do in .map.call?

1 Like
return str.split('')
  .map.call(str, function(char) {
  ...

I see no point in using call() here.

That code could be written:

return str.split('')
  .map(function(char) {
...

Thanks for clearing this up