Is there a standard way in JavaScript to easily compare two numbers where one or both can be in the form of e.g. '32k'. For example:
'32k' > 310
'2.5k' > 450
300 > 200
'2.5m' > '2.5k'
So that one easily could find the max value of an array like ... [300, '3k', '3.2k']. I could try to create my own function but I wondered if there is a standard way to do this?
If you have 'k', or 'm', then the "number" is actually a string object, so you would need to parse out the number before you could do a comparison. Since you are only looking for the max value, a simple loop, parse, convert, and compare should be sufficient. Here is an example that supports 'k', 'm', 'b', 't' (case insensitive).