5 kyu

Matching And Substituting

31 of 2,319g964

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’s 2.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".
Fundamentals

More By Author:

Check out these other kata created by g964

Stats:

CreatedOct 11, 2017
PublishedOct 11, 2017
Warriors Trained9510
Total Skips1706
Total Code Submissions29749
Total Times Completed2319
Shell Completions32
Python Completions727
JavaScript Completions535
Julia Completions12
Ruby Completions75
R Completions35
PowerShell Completions26
Go Completions90
Nim Completions7
PHP Completions93
Java Completions308
C# Completions136
Rust Completions126
Clojure Completions16
Racket Completions8
TypeScript Completions106
F# Completions10
Scala Completions31
Kotlin Completions50
Perl Completions12
Pascal Completions7
D Completions5
Total Stars182
% of votes with a positive feedback rating73% of 393
Total "Very Satisfied" Votes230
Total "Somewhat Satisfied" Votes114
Total "Not Satisfied" Votes49
Total Rank Assessments3
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • g964 Avatar
  • Blind4Basics Avatar
  • ZED.CWT Avatar
  • monadius Avatar
  • hobovsky Avatar
  • user8436785 Avatar
  • Just4FunCoder Avatar
Ad