Find the Shortest Word(s) in a Sentence in Javascript?
Create a function that accepts a string as an argument. Find its shortest word(s) and return them as an array sorted alphabetically (if there are multiple shortest words).
1 Answer
take this method its work correctly
function findShortestWords(str) {
const regex = /([A-Za-z’])+/g;
return str.match(regex)
.sort((a, b) => a.length - b.length)
.filter((el, i, arr) => el.length <= arr[0].length)
.map(el => el.toLowerCase())
.sort();
}
answer Link