Jscript: Take As Input An Array Of Strings, Return New Array Containing Only Strings With Fewer Than Five Characters
function fiveChar(inputArray) { var output = input.join(); return output; } console.log(fiveChar(['lion', 'gorilla', 'elk', 'kangaroo'])); How can I make this only return
Solution 1:
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;
});
}
Post a Comment for "Jscript: Take As Input An Array Of Strings, Return New Array Containing Only Strings With Fewer Than Five Characters"