-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.html
More file actions
35 lines (28 loc) · 806 Bytes
/
3.html
File metadata and controls
35 lines (28 loc) · 806 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
25
26
27
28
29
30
31
32
33
34
35
<html>
<head>
<p>All results are in the console.log. You can view it, by pressing shift+ctrl+j</p>
</head>
<body>
<script>
var reverseString = function(s) {
if(s.length === 0) return "";
let [index,len] = [0,s.length];
let word = "";
let result = "";
while(index < len){
while(index < len && s.charAt(index) == ' '){
index ++;
}
while(index < len && s.charAt(index) !== ' '){
word = `${word}${s.charAt(index)}`;
index ++;
}
result = word + ' ' + result;
word = "";
}
return result.trim();
};
console.log(reverseString("the sky is blue"));
</script>
</body>
</html>