I have some problem with this function that has firstValue(number), lastValue(number) and dataArray(array).The function has validation of firstvalue < lastValue and the number of records in the DataArray must be greater than 5. The function will search for data in the dataArray that has a value between the firstvalue and lastValue, sort the search results and display them on the console.
This is What I got so far. I have not used Javascript before, so any help would be appreciated.
let result ="";
function valueSelection(firstValue, lastValue, ...dataArray){
if(firstValue > lastValue) {
console.log("The last value must be greater than first value");
if(dataArray.length < 5) {
console.log("Numbers in dataArray must be more than 5");
} else {
console.log(result);
}
} else {
console.log(result);
}
}
valueSelection(5, 20 , [2, 25, 4, 14, 17, 30, 8])
the output I want is:
[8, 14, 17]
HandlingError :
valueSelection(15, 3 , [2, 25, 4, 14, 17, 30, 8])
output:"The last value must be greater than first value"
valueSelection(4, 17 , [2, 25, 4])
output: Numbers in dataArray must be more than 5
[8, 14, 17]?