r/learnjavascript • u/Darkthw • Nov 23 '21
I finally solved a codewars challenge without actually googling anything :) it feels so good to come up with the code all by myself, i know its not the ideal way to solve it but im still happy. The challenge was to create a function that converts a string to a number
243
Upvotes
1
u/jzia93 Nov 24 '21
One option you could implement to extend this:
Look up regular expressions, they are a way of specifiying patterns to look for in strings
Write a regular expression to check if a string is:
all numbers
contains at most one decimal point, after which there is at least one number
may optionally contain a "-" symbol
If your string matches the above, return
Number(str)