Skip to content

Files

Latest commit

 

History

History

Day 6

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Write a function to truncate a string to a certain number of words

  • Truncate a string to a certain number of words

Challenges (0/2 done)

  • truncateWithWordLimit("JavaScript is simple", 3) returns "JavaScript is simple"
  • truncateWithWordLimit("Codedamn is the best place to learn to code", 5) returns "Codedamn is the best place"
const str = 'JavaScript is simple but not easy to master';
const wordLimit = 3

function truncateWithWordLimit(str, wordLimit) {
    // write your solution here

    return
}

console.log(`Truncated string: ${truncateWithWordLimit(str, wordLimit)}`)