Matching And Substituting
Description:
I got lots of files beginning like this:
Program title: Primes
Author: Kern
Corporation: Gold
Phone: +1-503-555-0091
Date: Tues April 9, 2005
Version: 6.7
Level: Alpha
Here we will work with strings like the string data above and not with files.
The function change(s, prog, version)
given:
s=data, prog="Ladder" , version="1.1"
will return:
"Program: Ladder Author: g964 Phone: +1-503-555-0090 Date: 2019-01-01 Version: 1.1"
Rules:
The date should always be
"2019-01-01"
.The author should always be
"g964"
.Replace the current
"Program Title"
with the prog argument supplied to your function. Also remove"Title"
, so in the example case"Program Title: Primes"
becomes"Program: Ladder"
.Remove the lines containing
"Corporation"
and"Level"
completely.Phone numbers and versions must be in valid formats.
A valid version in the input string data is one or more digits followed by a dot, followed by one or more digits. So 0.6, 5.4, 14.275 and 1.99
are all valid, but versions like .6, 5, 14.2.7 and 1.9.9
are invalid.
A valid input phone format is +1-xxx-xxx-xxxx, where each x
is a digit.
If the phone or version format is not valid, return
"ERROR: VERSION or PHONE"
.If the version format is valid and the version is anything other than
2.0
, replace it with the version parameter supplied to your function. If it’s2.0
, don’t modify it.If the phone number is valid, replace it with
"+1-503-555-0090"
.
Note
- You can see other examples in the "Sample tests".
Similar Kata:
Stats:
Created | Oct 11, 2017 |
Published | Oct 11, 2017 |
Warriors Trained | 9510 |
Total Skips | 1706 |
Total Code Submissions | 29749 |
Total Times Completed | 2319 |
Shell Completions | 32 |
Python Completions | 727 |
JavaScript Completions | 535 |
Julia Completions | 12 |
Ruby Completions | 75 |
R Completions | 35 |
PowerShell Completions | 26 |
Go Completions | 90 |
Nim Completions | 7 |
PHP Completions | 93 |
Java Completions | 308 |
C# Completions | 136 |
Rust Completions | 126 |
Clojure Completions | 16 |
Racket Completions | 8 |
TypeScript Completions | 106 |
F# Completions | 10 |
Scala Completions | 31 |
Kotlin Completions | 50 |
Perl Completions | 12 |
Pascal Completions | 7 |
D Completions | 5 |
Total Stars | 182 |
% of votes with a positive feedback rating | 73% of 393 |
Total "Very Satisfied" Votes | 230 |
Total "Somewhat Satisfied" Votes | 114 |
Total "Not Satisfied" Votes | 49 |
Total Rank Assessments | 3 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |