-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoveExclamationMarks.js
More file actions
27 lines (22 loc) · 921 Bytes
/
Copy pathremoveExclamationMarks.js
File metadata and controls
27 lines (22 loc) · 921 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
//Write function RemoveExclamationMarks which removes all exclamation marks from a given string.
function removeExclamationMarks(s){
return s.split('!').join('');
}
// Example usage:
console.log(removeExclamationMarks("Hello! World!!")); // "Hello World"
console.log(removeExclamationMarks("Wow!!! This is great!!!")); // "Wow This is great"
console.log(removeExclamationMarks("No exclamation mark here")); // "No exclamation mark here"
//OR
function removeExclamationMarks(s) {
let result = '';
for (let i = 0; i < s.length; i++) {
if (s[i] !== '!') {
result += s[i];
}
}
return result;
}
// Example usage:
console.log(removeExclamationMarks("Hello! World!!")); // "Hello World"
console.log(removeExclamationMarks("Wow!!! This is great!!!")); // "Wow This is great"
console.log(removeExclamationMarks("No exclamation mark here")); // "No exclamation mark here"