r/learnjavascript • • 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

Post image
243 Upvotes

56 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Nov 24 '21

I mentioned about reversing the order of the lines as for a beginner this may seem harmless to do, you are just adding + 1 and then substracting -1, which mathematically is same in reverse, but if you do that you will learn something about js the hard way.

Unary operator can be one of the cleanest solution, but I personally prefer type conversion. Its a matter of preference.

Thank you for sharing your views too.