From 876c2efd659c0a6f27c5f919ac8c82ed0870837c Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 13 Sep 2016 17:56:57 -0400 Subject: [PATCH 1/8] data_types.php --- data_types.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 data_types.php diff --git a/data_types.php b/data_types.php new file mode 100644 index 0000000..d24b576 --- /dev/null +++ b/data_types.php @@ -0,0 +1,45 @@ + From bb2004ca364e73642d8b63e2b82f7e32af20ea4c Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 13 Sep 2016 18:02:44 -0400 Subject: [PATCH 2/8] test 2 --- data_types.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/data_types.php b/data_types.php index d24b576..3cef2f5 100644 --- a/data_types.php +++ b/data_types.php @@ -18,12 +18,13 @@ function convert_to_float($input){ function convert_to_string($input){ //array to string code here should return comma seperated values in a string - if (bool is_array ( mixed $input )){ - for(var i = 0; i<$input.Length; i++){ - echo $input[i]; - } - } - else{echo (string)$input;} + // if (bool is_array ( mixed $input )){ + // for(var i = 0; i<$input.Length; i++){ + // echo $input[i]; + // } + // } + // else{echo (string)$input;} + echo (string)$input; } function convert_to_bool($input){ From 6c0e17c29b5e501aad4f559ad1f724b18ad902be Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 13 Sep 2016 18:07:24 -0400 Subject: [PATCH 3/8] switched again --- data_types.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/data_types.php b/data_types.php index 3cef2f5..c132349 100644 --- a/data_types.php +++ b/data_types.php @@ -9,36 +9,35 @@ $input = "Ello World "; function convert_to_int($input){ - echo (int)$input; + return (int)$input; } function convert_to_float($input){ - echo (double)$input; + return (double)$input; } function convert_to_string($input){ - //array to string code here should return comma seperated values in a string - // if (bool is_array ( mixed $input )){ - // for(var i = 0; i<$input.Length; i++){ - // echo $input[i]; - // } - // } - // else{echo (string)$input;} - echo (string)$input; +// array to string code here should return comma seperated values in a string + if (bool is_array ( mixed $input )){ + for(var i = 0; i<$input.Length; i++){ + return $input[i]; + } + } + else{return (string)$input;} } function convert_to_bool($input){ - echo false; + return false; } function convert_to_array($input){ - echo array($input); + return array($input); } function convert_to_null($input){ if( $input == 0 || $input == false){ - echo null; - }else{echo true;} + return null; + }else{return true;} } echo convert_to_string($input); From 02b4456cabe38eca30c62f1820468df09ec39ba0 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 13 Sep 2016 18:09:45 -0400 Subject: [PATCH 4/8] removed space from is_array --- data_types.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_types.php b/data_types.php index c132349..3b3625a 100644 --- a/data_types.php +++ b/data_types.php @@ -18,7 +18,7 @@ function convert_to_float($input){ function convert_to_string($input){ // array to string code here should return comma seperated values in a string - if (bool is_array ( mixed $input )){ + if (bool is_array(mixed $input)){ for(var i = 0; i<$input.Length; i++){ return $input[i]; } From 6cb106a5dee8611fac8472e983975359b15aa107 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 13 Sep 2016 18:12:53 -0400 Subject: [PATCH 5/8] removed value --- data_types.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_types.php b/data_types.php index 3b3625a..cde637b 100644 --- a/data_types.php +++ b/data_types.php @@ -6,7 +6,7 @@ //Return `[]` for `convert_to_array()` //Return `null` for `convert_to_null()` -$input = "Ello World "; +// $input = "Ello World "; function convert_to_int($input){ return (int)$input; From 55b22ac087eda9f7801b7ac0ffd057eea3ebc073 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 13 Sep 2016 18:58:47 -0400 Subject: [PATCH 6/8] var_dump test --- data_types.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/data_types.php b/data_types.php index cde637b..85885c7 100644 --- a/data_types.php +++ b/data_types.php @@ -6,24 +6,30 @@ //Return `[]` for `convert_to_array()` //Return `null` for `convert_to_null()` -// $input = "Ello World "; +$input = array("somethign", "two", "Three"); function convert_to_int($input){ return (int)$input; } + function convert_to_float($input){ return (double)$input; } function convert_to_string($input){ -// array to string code here should return comma seperated values in a string - if (bool is_array(mixed $input)){ - for(var i = 0; i<$input.Length; i++){ - return $input[i]; + //array to string code here should return comma seperated values in a string + if (is_array ($input)){ + $length = count($input); + $output = ""; + + for($i = 0; $i < $length; $i++){ + $output .= $input[$i] . ", "; } + return $output; } - else{return (string)$input;} + else{ return (string)$input;} + // return (string)$input; } function convert_to_bool($input){ @@ -40,6 +46,4 @@ function convert_to_null($input){ }else{return true;} } -echo convert_to_string($input); - ?> From 00bd2a8e695ab786614dbd15624b509c9d2992ea Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 13 Sep 2016 19:19:53 -0400 Subject: [PATCH 7/8] working through unit tests --- data_types.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/data_types.php b/data_types.php index 85885c7..7707fec 100644 --- a/data_types.php +++ b/data_types.php @@ -6,7 +6,7 @@ //Return `[]` for `convert_to_array()` //Return `null` for `convert_to_null()` -$input = array("somethign", "two", "Three"); +$input = array(array(2, 3), array(2, 3)); function convert_to_int($input){ return (int)$input; @@ -24,7 +24,9 @@ function convert_to_string($input){ $output = ""; for($i = 0; $i < $length; $i++){ - $output .= $input[$i] . ", "; + if($i+1 == $length) //checks if end of line removes last comma + {$output .= $input[$i];} + else{$output .= $input[$i] . ", ";} } return $output; } @@ -33,11 +35,14 @@ function convert_to_string($input){ } function convert_to_bool($input){ - return false; + return (bool)$input; } function convert_to_array($input){ - return array($input); + if ($input == null){ + return array(); + } + else{return array($input);} } function convert_to_null($input){ @@ -46,4 +51,6 @@ function convert_to_null($input){ }else{return true;} } +var_dump(convert_to_array($input)); + ?> From 1108a212bc839535d846d4c90c04f70d201d46b4 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 13 Sep 2016 20:03:45 -0400 Subject: [PATCH 8/8] take 201413121 --- data_types.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/data_types.php b/data_types.php index 7707fec..245f982 100644 --- a/data_types.php +++ b/data_types.php @@ -6,7 +6,7 @@ //Return `[]` for `convert_to_array()` //Return `null` for `convert_to_null()` -$input = array(array(2, 3), array(2, 3)); +$input = array('', array('')); function convert_to_int($input){ return (int)$input; @@ -42,7 +42,11 @@ function convert_to_array($input){ if ($input == null){ return array(); } - else{return array($input);} + //Test if Array return -- else place in array + elseif (is_array ($input)){ + return $input;} + else{ + return array($input);} } function convert_to_null($input){