Created
January 1, 2024 01:40
-
-
Save JidLaurence/398c40c9afadc3503509c42c6b6b37d5 to your computer and use it in GitHub Desktop.
Test 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countCharacterOccurrences({S, N, C}) { | |
// Total the number of times S should repeated to get variable N | |
// Calculate the number times of variable S should be repeated to reach the value of N | |
const totalRepeted = Math.ceil(N / S.length); | |
// Repeat the variable S to reach the desired length | |
const repeatedString = S.repeat(totalRepeted); | |
// Count occurrences of the variable C in the repeated string | |
return [...repeatedString].filter(char => char === C).length; | |
} | |
const result = countCharacterOccurrences({S:"abcd", N:11, C: 'a'}) | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment