Convert a string to numbers in an array and define by even and odd values code example
Example: Convert a string to numbers in an array and define by even and odd values
// Convert a string to numbers in an array and define by even and odd values
function reverseOdd(str) {
let odd = [];
let even = [];
let arrayStr = str.split(" ").map(function(element){return element.length;});
for (var i = 0; i < arrayStr.length; i++) {
if (arrayStr[i] % 2 === 0) {
even.push(arrayStr[i]);
}else {
odd.push(arrayStr[i]);
}
}
const returnObject = {
odd,
even,
};
return returnObject;
}
console.log(reverseOdd("Bananas")); // "even"
console.log(reverseOdd("One two three four")); // "odd odd odd even"