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.
// 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'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment