summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-09-03 16:52:15 +0530
committerAndinus <andinus@nand.sh>2021-09-03 16:52:15 +0530
commitcbc991d678e6c7ee84471c7c6561a6084bb85ccd (patch)
tree2e79c4eb1819da46d6a3daea34c7e59f68e7669b
parent1bbb981f09fb0e935d429d94d68ab10522aca321 (diff)
downloadexercism-cbc991d678e6c7ee84471c7c6561a6084bb85ccd.tar.gz
Raku: Phone Number: Remove duplicate code with the use of proceed
-rw-r--r--raku/phone-number/Phone.rakumod16
1 files changed, 4 insertions, 12 deletions
diff --git a/raku/phone-number/Phone.rakumod b/raku/phone-number/Phone.rakumod
index ef214b1..66a9e24 100644
--- a/raku/phone-number/Phone.rakumod
+++ b/raku/phone-number/Phone.rakumod
@@ -18,19 +18,12 @@ sub clean-number(Str $number --> Str) is export {
     # <punct> matches "(";
     die @errors[4] if $number.contains: /<[!:]>/;
 
-    given $number.comb.grep(/\d/)>>.Int {
+    my Int @num = $number.comb.grep(/\d/)>>.Int;
+    given @num {
         when .elems == 11 {
             die @errors[0] if .[0] !== 1;
-
-            # Area code.
-            die @errors[5] if .[1] == 0;
-            die @errors[6] if .[1] == 1;
-
-            # Exchange code.
-            die @errors[7] if .[4] == 0;
-            die @errors[8] if .[4] == 1;
-
-            return .skip.join;
+            @num .= skip;
+            proceed;
         }
         when .elems == 10 {
             # Area code.
@@ -45,6 +38,5 @@ sub clean-number(Str $number --> Str) is export {
         }
         when .elems > 11 { die @errors[1] }
         when .elems < 10 { die @errors[2] }
-        default { return .join }
     }
 }