Sha256: dfaf14edb72ed23c4f462bc04c774d7c27e4d9a48b359de9ba5ff9a8c07f9ab7

Contents?: true

Size: 1.02 KB

Versions: 203

Compression:

Stored size: 1.02 KB

Contents

parse_phone_number <- function(number_string) {
  
  # If the number is less than 10 digits assume that it is bad number
  # If the number is 10 digits assume that it is good, unless area or exchange 
  #  code are not between 2 to 9
  # If the number is 11 digits and the first number is 1, use the last 10 digits
  # If the number is 11 digits and the first number is not 1, it is a bad number
  # If the number is more than 11 digits assume that it is a bad number
 
  # Check for letters
  if (grepl("[A-z]", number_string)) {
    return (NULL)
  }
  
  # Remove non-digit characters from number string
  cleaned <- gsub("[^0-9]", "", number_string)
  
  if (nchar(cleaned) < 10) {
    NULL
  }
  else if (nchar(cleaned) == 10 & (substr(cleaned, 1, 1) %in% c("0", "1") |
                                   substr(cleaned, 4, 4) %in% c("0", "1"))) {
    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

203 entries across 203 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.179 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.178 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.177 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.176 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.175 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.174 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.173 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.172 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.171 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.170 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.169 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.167 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.166 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.165 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.164 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.163 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.162 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.161 tracks/r/exercises/phone-number/example.R
trackler-2.2.1.160 tracks/r/exercises/phone-number/example.R