Skip to content

Commit dbbd78f

Browse files
committed
add more codes
1 parent da6572e commit dbbd78f

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

Snippets/Strings/charCount.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function charCount(str){
2+
let dict = {}
3+
for(const c of str){
4+
if(c in dict){
5+
dict[c]+=1
6+
}else{
7+
dict[c] = 1
8+
}
9+
}
10+
return dict
11+
}
12+
13+
charCount("Hello")

Snippets/Strings/removeSpaces.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function removeSpaces(str){
2+
let ans = str.split(" ").join("");
3+
return ans
4+
}
5+
6+
console.log(removeSpaces("Soham is a good guy"));

Snippets/Strings/replaceString.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function replaceChar(str,c1,c2){
2+
let regex = new RegExp(c1,"g");
3+
console.log(regex)
4+
let ans = str.replace(regex,'2');
5+
return ans
6+
}
7+
8+
console.log(replaceChar("Soham is a good guy", "o","d"));

Snippets/Strings/substrings.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function substring(str){
2+
let arr = []
3+
for(let i=1; i<=str.length;i++){
4+
let temp = "";
5+
for(let j=0; j<=str.length-i;j++){
6+
temp+=str[j];
7+
}
8+
arr.push(temp);
9+
}
10+
console.log(arr)
11+
12+
}
13+
14+
console.log(substring("1234567"))

0 commit comments

Comments
 (0)