- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreverseWords.js
More file actions
Latest commit
24 lines (20 loc) · 596 Bytes
/
Copy pathreverseWords.js
File metadata and controls
24 lines (20 loc) · 596 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
letreverseWords=(myWord,cb)=>{
letreverseWords='';
letstrArray=myWord.split(" ");
strArray.forEach(currentString=>{
letstringLength=currentString.length;
for(leti=stringLength-1;i>=0;i--){
reverseWords+=currentString[i];
}
if(strArray.indexOf(currentString)!=strArray.length-1){
reverseWords+=' ';
}
});
returncb(null,reverseWords);
};
reverseWords('This is a string of words.',(err,reverseWords)=>{
if(err){
}else{
console.log(reverseWords);
}
});