why parseFloat(Number.MAX_VALUE)
is used in javascript coin change solution https://www.educative.io/module/page/xGD3yRS9rp2LK46J6/10370001/6171773541548032/5163864674271232? why not to use just Infinity for example
Hello @Alexey_Tomin,
You can use either Number.MAX_VALUE
or Infinity
in the provided code, as both options will work effectively for the coin change algorithm. The use of Number.MAX_VALUE
in the code initializes the counter variable with a large finite number, which can then be printed out on the console for debugging purposes.
It’s worth noting that when Infinity
is printed to the console, it displays “Infinity” rather than a numerical value. To ensure consistency and ease of debugging, using Number.MAX_VALUE
is a safer choice. This approach ensures that the initialized value is a finite number while still being large enough to effectively serve its purpose in comparisons within the algorithm.
Feel free to experiment with both options and if you have any more questions, please don’t hesitate to ask!
Thanks.