find PhoneNum in string

by joplomacedo

JavaScript

const reoodlesStartMark = '#:';
const acceptableNumChars = ['+', ' ', '-', '(', ')'];


function findIdxOfNumOrPlusSign(str) {
  return str
    .split('')
    .findIndex(char => !isNaN(char) || char === '+');
}

const findPhoneNum = (function() {

  return function(str) {
    let phoneNum = '';

    const phoneNumStartMarkIdx = str.indexOf(phoneNumStartMark);

    if (phoneNumStartMarkIdx === -1) {
      return null;
    }

    const phoneNumStartIdx = phoneNumStartMarkIdx + phoneNumStartMark.length;
    const phoneNumAtStartStr = str.substring(phoneNumStartIdx).trim();
    const phoneNumAtStartStrAsArr = phoneNumAtStartStr.split('');

    for (let i = 0; i < phoneNumAtStartStrAsArr.length; i++) {
      let char = phoneNumAtStartStrAsArr[i];

      if (!isNaN(char)) {
        phoneNum += char;

      } else if (char === '+') {

        if (!phoneNum.length) {
          phoneNum += char;
        }

      } else if (!acceptableNumChars.includes(char)) {
        break;
      }
    }

    return phoneNum.length ? phoneNum : null;
  };

})();


const findFirstPotentialPhoneNum = (str) => {
  const firstRelevantCharIdx = findIdxOfNumOrPlusSign(str);
  const firstRelevantChar = str(firstRelevantCharIdx);

  if (firstRelevantChar == -1) {
    return null;
  }

  let potentialPhoneNum = firstRelevantChar; //we'll be adding to this graduall
  let strAsArr = str.split('');
  
  let followingChar = str[firstRelevantCharIdx + 1];
  
  if ( firstRelevantChar == '0' ) {
  
  	  let followingChar = str[firstRelevantCharIdx + 1];
      
      if ( followingChar == "0" ) {

      }
  }

  for (let i = 0; i < strAsArr.length; i++) {
    let char = strAsArr[i];

    if (!isNaN(char)) {
      potentialPhoneNum += char;

    } else if (!acceptableNumChars.includes(char)) {
      break;
    }
  }
};


const x = (str) => {

  const reoodlesStartMarkIdx = str.indexOf(reoodlesStartMark);
  
  if ( reoodlesStartMarkIdx !== -1 ) {
  	
    
  } else {
  
  
  }

}


//TESTS

const test =...