peterschussheim
10/21/2016 - 5:17 PM

parseInt

parseInt

// parseInt parse a string arg and returns an integer of the specified radix.

function myParseInt(str) {
  // if str contains a-c, return "NaN"
  const regex = /[a-zA-Z]/g;
  const match = str.match(regex);
  const rep = str.replace(regex, "");
    return parseInt(str, 10);
}

myParseInt("5 friends")
myParseInt("2")
myParseInt("16.5")


const test = "5 friends";
const regex = /[a-zA-Z]/g;
const match = test.match(regex);
const replace = match.replace(regex, 10)

parseInt

This Gist was automatically created by Carbide, a free online programming environment.

You can view a live, interactive version of this Gist here.