So I have here some JS code for getting either a singular value or, if there's a 'range' of prices separated by ' - ', getting the highest value:
function getPrice() {
var str = ("£25 - £36");
var val;
if (str.indexOf('-') > -1) {
val = Number(str.replace(/[^0-9.-]+/g, "").split('-')[1], 10);
} else {
val = Number(str.replace(/[^0-9.-]+/g, "").split('-')[0], 10);
}
return val;
}
How would I modify this so that it gets the lowest value instead?
This 'range' will always be either in the format of £25 or £13 - £72 and it will always be in pounds. The highest value will always be the last; in this context they are functionally the same.