0
Your function will receive a string as parameter. Separate this string using the ' ' character and return a string containing the largest number and the smallest number (necessarily in this order).
function maiorEMenor(numbers) {
var numeros = [];
for (let i = 0; i < numbers.length; i +=2) {
numeros.push(parseInt(numbers.substr(i, i+1)))
}
var maior = Math.max.apply(null, numeros)
var menor = Math.min.apply(null, numeros)
return maior.toString() + ' ' + menor.toString()
}
The code works unless the parameter starts with negative numbers or is only a number.
Example: if the input is '1 2 3 4 5' it returns '5 1';
but if the input is '42' it returns '4 2' instead of '42 42'
and with negative entries it gets returns Nan
Substr is selected 1 Character at a time, tries with String split
– ruansenadev