mirror of
https://bitbucket.org/Mattrixwv/typescriptclasses.git
synced 2025-12-06 18:33:59 -05:00
Added findNumOccurrence function
This commit is contained in:
@@ -605,3 +605,17 @@ function swapString(str: string, first: number, second: number): string{
|
||||
|
||||
return tempStr;
|
||||
}
|
||||
|
||||
//This function returns the number of times the character occurs in the string
|
||||
export function findNumOccurrence(str: string, ch: string){
|
||||
let num: number = 0; //Set the number of occurrences to 0 to start
|
||||
//Loop through every character in the string and compare it to the character passed in
|
||||
for(let strCh of str){
|
||||
//If the character is the same as the one passed in increment the counter
|
||||
if(strCh == ch){
|
||||
++num;
|
||||
}
|
||||
}
|
||||
//Return the number of times the character appeared in the string
|
||||
return num;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user