DEV Community

loading...

Discussion on: What’s your alternative solution? Challenge #54

Collapse
trasherdk profile image
TrasherDK

This could probably be reduced even more:

const text = "Create a function to return the longest word(s) in a sentance.";

let result = text.replace(/[^a-zA-Z ]/g,'').split(' ').sort((a,b) => {
    return a.length - b.length;
} )

let longest = result[result.length-1].length
result = result.filter( (a) => {
  return a.length >= longest
  })
console.log(result)