Skip to content

Instantly share code, notes, and snippets.

@solehudin5699
Created March 25, 2022 06:42
Show Gist options
  • Save solehudin5699/7a4abbbbae3e90a87935c5fb9bb5e9d3 to your computer and use it in GitHub Desktop.
Save solehudin5699/7a4abbbbae3e90a87935c5fb9bb5e9d3 to your computer and use it in GitHub Desktop.

Revisions

  1. solehudin5699 created this gist Mar 25, 2022.
    41 changes: 41 additions & 0 deletions manipulate-sentence.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    // 3.___
    const convertToStar=(sentences="aa aa")=>{
    const sentArr = sentences.split(' ');
    let newSentences=[]
    sentArr.forEach((word,idx)=>{
    if(word.length>2){
    let newWord='';
    const lengthWord = word.length
    word.split('').forEach((char,idx)=>{
    if(idx>0&&idx<lengthWord-1){
    newWord+="*"
    }else{
    newWord+=char
    }
    })
    newSentences[idx]=newWord
    }else{
    newSentences[idx]=word
    }
    })
    return newSentences.join(' ')
    }

    console.log(convertToStar('bootcamp fullstack java'))

    // 4._____
    const lengthSentences=(sentences)=>{
    const length = sentences.replace(/\s/g, "").length
    return length
    }

    console.log(lengthSentences('bootcamp fullstack java'))


    // 5.____
    const totalWords=(sentences)=>{
    const length = sentences.split(' ').length
    return length
    }

    console.log(totalWords('bootcamp fullstack java'))