DEV Community

Discussion on: Daily Challenge #228 - Best Profit in Single Sale

Collapse
 
aminnairi profile image
Amin

Nice one, but there are some things that bother me in the code.

You could have replaced the var by a let or a const in the first line since you are using let later.

You can increase the speed execution of your algorithm by caching the length of the prices variables, which is not changing over the course of your iterations.

Your variable maxCurr lacks a variable declaration keyword: either let or const.

Also, you are using the maxCurr variable before even declaring it. That does not make sense.

I tried to run it but it threw some exceptions, did you run it on your local machine?

Collapse
 
akhilpokle profile image
Akhil • Edited

Thanks for pointing out, it's a typo. My bad. I have updated the code.