Function to map letters to numbers I have a method that converts characters to numbers.
It expects a single alphabetical character and returns the equivalent number.
For example, if A is provided it returns 1, for B it returns 2.
If an array is passed, it returns the message "array not accepted".

function characterToNumberCoverter(character) {
  if (Array.isArray(character)) {
    return { status: "failure", message: "array not accepted" };}
  character = character.toUpperCase();
  let myRegExp = /[A-Z]/;
  if (myRegExp.test(character)) {
    return character.charCodeAt(0) - 64;}}


The method returns an object if the input is invalid and an integer if the input is valid. The method is invoked like this:

let intConvertedInt=characterToNumberCoverter('A');


This works fine when the input is valid. What is a better way to handle the use case where an invalid input is passed? Example in which the result will be an object:

    let intConvertedInt=characterToNumberCoverter({});


Are there any other function design patterns that I should be following?
Why not just compare directly to the charcode?

function characterToNumberCoverter(character) {
  let code = character.toUpperCase().charCodeAt(0);
  if (code &gt; 64 &amp;&amp; code &lt; 91) return code - 64
  return 0
}