7 kyu
Replace every nth
1,026 of 4,446user5036852
Description:
Task
Write a method, that replaces every nth char oldValue with char newValue.
Inputs
text
: the string to modifyn
: change the target letter everyn
th occurrenciesold_value
(or similar): the targetted characternew_value
(or similar): the character to use as replacement
Note for untyped languages: all inputs are always valid and of their expected type.
Rules
- Your method has to be case sensitive!
- If n is 0 or negative or if it is larger than the count of the oldValue, return the original text without a change.
Example:
n: 2
old_value: 'a'
new_value: 'o'
"Vader said: No, I am your father!"
1 2 3 4 -> 2nd and 4th occurence are replaced
"Vader soid: No, I am your fother!"
As you can see in the example: The first changed is the 2nd 'a'. So the start is always at the nth suitable char and not at the first!
Algorithms
Strings
Similar Kata:
Stats:
Created | Oct 11, 2016 |
Published | Oct 11, 2016 |
Warriors Trained | 10106 |
Total Skips | 950 |
Total Code Submissions | 20428 |
Total Times Completed | 4446 |
JavaScript Completions | 1026 |
C# Completions | 235 |
Java Completions | 953 |
F# Completions | 36 |
C++ Completions | 875 |
TypeScript Completions | 146 |
Python Completions | 875 |
C Completions | 375 |
Ruby Completions | 113 |
CoffeeScript Completions | 14 |
Clojure Completions | 20 |
COBOL Completions | 3 |
Total Stars | 110 |
% of votes with a positive feedback rating | 91% of 863 |
Total "Very Satisfied" Votes | 722 |
Total "Somewhat Satisfied" Votes | 125 |
Total "Not Satisfied" Votes | 16 |
Total Rank Assessments | 12 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |