Skip to content

Instantly share code, notes, and snippets.

@JidLaurence
Created January 1, 2024 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JidLaurence/398c40c9afadc3503509c42c6b6b37d5 to your computer and use it in GitHub Desktop.
Save JidLaurence/398c40c9afadc3503509c42c6b6b37d5 to your computer and use it in GitHub Desktop.
Test 2
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