I have this inputs:
var str1 = "21";
var str2 = "1.";
var str3 = "5. test"
var str4 = "- something";
I want this outputs:
// 21
// 1
// 5
// 0
- First case doesn't need to convert.
- Second case need to use
Number();
. - Third case using
.replace(/(\d)/g, "$1");
. - But how can I do fourth case? Actually I want to replace a string with
0
if it isn't containing number.
My question seems easy, but that's 30min which I'm thinking about it and still I couldn't solve it.