-1
function fiveChar(inputArray) {
    var output = input.join();
    return output;
}

console.log(fiveChar(['lion', 'gorilla', 'elk', 'kangaroo']));

How can I make this only return lion and elk, given they're under five characters?

Thanks!

tektiv
  • 14,010
  • 5
  • 61
  • 70

1 Answers1

0

You can use .filter() to filter the array down into a new array with strings that have a .length less than 6 characters.

function fiveChar(inputArray) {
  return inputArray.filter(function(in) { 
    return in.length < 6;
  });
}
Gavin
  • 4,365
  • 1
  • 18
  • 27