Sha256: 7987a6aa1b52983893469a93b6dc64cba115fb18c80ca3397468a56f4fd22e03

Contents?: true

Size: 861 Bytes

Versions: 87

Compression:

Stored size: 861 Bytes

Contents

parsePhoneNumber <- function(numberString) {
  
  # If the phone number is less than 10 digits assume that it is bad number
  # If the phone number is 10 digits assume that it is good
  # If the phone number is 11 digits and the first number is 1, trim the 1 and use the last 10 digits
  # If the phone number is 11 digits and the first number is not 1, then it is a bad number
  # If the phone number is more than 11 digits assume that it is a bad number
 
  # Check for letters
  if (grepl("[A-z]", numberString)) {
    return (NULL)
  }
  
  # Remove non-digit characters from number string
  cleaned <- gsub("[^0-9]", "", numberString)
  
  if (nchar(cleaned) < 10) {
    NULL
  } 
  else if (nchar(cleaned) == 10) {
    cleaned
  } 
  else if (nchar(cleaned) == 11 & substr(cleaned, 1, 1) == "1") {
    substr(cleaned, 2, 11)
  }
  else {
    NULL
  }
 
}

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
trackler-2.1.0.21 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.20 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.19 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.18 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.17 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.16 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.15 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.14 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.13 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.12 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.11 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.10 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.9 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.8 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.7 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.6 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.5 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.4 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.3 tracks/r/exercises/phone-number/example.R
trackler-2.1.0.2 tracks/r/exercises/phone-number/example.R