Is it possible to make easier this code? [closed]
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
-1
down vote
favorite
That was a question from interview. This code works, but it is very difficult to maintain. What should be changed in order to make this easier? Thanks for answers!
$adSpaceCorrect = !empty($payload->adSpaces) && is_array($payload->adSpaces);
if ($adSpaceCorrect)
if (count($payload->adSpaces)>0)
foreach($payload->adSpaces as $adSpace)
if(!is_string(adSpace))
$dataStatus.='Ad Spaces contains a non-string value.';
$adSpaceCorrect=false;
break;
else
$dataStatus.='Ad Spaces is an empty array.';
$adSpaceCorrect=false;
php
closed as unclear what you're asking by Sam Onela, Heslacher, Mast, t3chb0t, Ludisposed Jan 8 at 8:47
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |Â
up vote
-1
down vote
favorite
That was a question from interview. This code works, but it is very difficult to maintain. What should be changed in order to make this easier? Thanks for answers!
$adSpaceCorrect = !empty($payload->adSpaces) && is_array($payload->adSpaces);
if ($adSpaceCorrect)
if (count($payload->adSpaces)>0)
foreach($payload->adSpaces as $adSpace)
if(!is_string(adSpace))
$dataStatus.='Ad Spaces contains a non-string value.';
$adSpaceCorrect=false;
break;
else
$dataStatus.='Ad Spaces is an empty array.';
$adSpaceCorrect=false;
php
closed as unclear what you're asking by Sam Onela, Heslacher, Mast, t3chb0t, Ludisposed Jan 8 at 8:47
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
What did the interviewer ask?
â Mast
Jan 5 at 17:39
What exactly do you mean by "easier"? easier to read? easier to maintain? Also, Your title is too common a request to be appropriate for this site. What task does this code accomplish? Please tell us, and also make that the title of the question. "State what your code does in your title, not your main concerns about it.". Please read How to Ask.
â Sam Onela
Jan 5 at 17:49
@SamOnela - It's evident to me that he's not a native English speaker, maybe he doesn't know a better word than "easy." Also, he's new here, perhaps you could point out the Edit button and explain that's how he is to update his title to state the function of the code - although, if the code was given to him in an interview he may not know the function of it.
â Occam's Razor
Jan 5 at 18:13
Yeah I should have included[edit]
in my comment; actually this code looks like a stub until the other variables are declared/defined here.... which makes this question off-topic...
â Sam Onela
Jan 5 at 19:29
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
That was a question from interview. This code works, but it is very difficult to maintain. What should be changed in order to make this easier? Thanks for answers!
$adSpaceCorrect = !empty($payload->adSpaces) && is_array($payload->adSpaces);
if ($adSpaceCorrect)
if (count($payload->adSpaces)>0)
foreach($payload->adSpaces as $adSpace)
if(!is_string(adSpace))
$dataStatus.='Ad Spaces contains a non-string value.';
$adSpaceCorrect=false;
break;
else
$dataStatus.='Ad Spaces is an empty array.';
$adSpaceCorrect=false;
php
That was a question from interview. This code works, but it is very difficult to maintain. What should be changed in order to make this easier? Thanks for answers!
$adSpaceCorrect = !empty($payload->adSpaces) && is_array($payload->adSpaces);
if ($adSpaceCorrect)
if (count($payload->adSpaces)>0)
foreach($payload->adSpaces as $adSpace)
if(!is_string(adSpace))
$dataStatus.='Ad Spaces contains a non-string value.';
$adSpaceCorrect=false;
break;
else
$dataStatus.='Ad Spaces is an empty array.';
$adSpaceCorrect=false;
php
asked Jan 5 at 17:32
Yrtymd
11
11
closed as unclear what you're asking by Sam Onela, Heslacher, Mast, t3chb0t, Ludisposed Jan 8 at 8:47
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Sam Onela, Heslacher, Mast, t3chb0t, Ludisposed Jan 8 at 8:47
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
What did the interviewer ask?
â Mast
Jan 5 at 17:39
What exactly do you mean by "easier"? easier to read? easier to maintain? Also, Your title is too common a request to be appropriate for this site. What task does this code accomplish? Please tell us, and also make that the title of the question. "State what your code does in your title, not your main concerns about it.". Please read How to Ask.
â Sam Onela
Jan 5 at 17:49
@SamOnela - It's evident to me that he's not a native English speaker, maybe he doesn't know a better word than "easy." Also, he's new here, perhaps you could point out the Edit button and explain that's how he is to update his title to state the function of the code - although, if the code was given to him in an interview he may not know the function of it.
â Occam's Razor
Jan 5 at 18:13
Yeah I should have included[edit]
in my comment; actually this code looks like a stub until the other variables are declared/defined here.... which makes this question off-topic...
â Sam Onela
Jan 5 at 19:29
add a comment |Â
What did the interviewer ask?
â Mast
Jan 5 at 17:39
What exactly do you mean by "easier"? easier to read? easier to maintain? Also, Your title is too common a request to be appropriate for this site. What task does this code accomplish? Please tell us, and also make that the title of the question. "State what your code does in your title, not your main concerns about it.". Please read How to Ask.
â Sam Onela
Jan 5 at 17:49
@SamOnela - It's evident to me that he's not a native English speaker, maybe he doesn't know a better word than "easy." Also, he's new here, perhaps you could point out the Edit button and explain that's how he is to update his title to state the function of the code - although, if the code was given to him in an interview he may not know the function of it.
â Occam's Razor
Jan 5 at 18:13
Yeah I should have included[edit]
in my comment; actually this code looks like a stub until the other variables are declared/defined here.... which makes this question off-topic...
â Sam Onela
Jan 5 at 19:29
What did the interviewer ask?
â Mast
Jan 5 at 17:39
What did the interviewer ask?
â Mast
Jan 5 at 17:39
What exactly do you mean by "easier"? easier to read? easier to maintain? Also, Your title is too common a request to be appropriate for this site. What task does this code accomplish? Please tell us, and also make that the title of the question. "State what your code does in your title, not your main concerns about it.". Please read How to Ask.
â Sam Onela
Jan 5 at 17:49
What exactly do you mean by "easier"? easier to read? easier to maintain? Also, Your title is too common a request to be appropriate for this site. What task does this code accomplish? Please tell us, and also make that the title of the question. "State what your code does in your title, not your main concerns about it.". Please read How to Ask.
â Sam Onela
Jan 5 at 17:49
@SamOnela - It's evident to me that he's not a native English speaker, maybe he doesn't know a better word than "easy." Also, he's new here, perhaps you could point out the Edit button and explain that's how he is to update his title to state the function of the code - although, if the code was given to him in an interview he may not know the function of it.
â Occam's Razor
Jan 5 at 18:13
@SamOnela - It's evident to me that he's not a native English speaker, maybe he doesn't know a better word than "easy." Also, he's new here, perhaps you could point out the Edit button and explain that's how he is to update his title to state the function of the code - although, if the code was given to him in an interview he may not know the function of it.
â Occam's Razor
Jan 5 at 18:13
Yeah I should have included
[edit]
in my comment; actually this code looks like a stub until the other variables are declared/defined here.... which makes this question off-topic...â Sam Onela
Jan 5 at 19:29
Yeah I should have included
[edit]
in my comment; actually this code looks like a stub until the other variables are declared/defined here.... which makes this question off-topic...â Sam Onela
Jan 5 at 19:29
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
- The check for
count($payload->adSpaces)>0
is redundant because you already know it's a non-empty array as per$adSpaceCorrect
. - Once you correct the nested
if
s it becomes clear that the second$adSpaceCorrect=false;
is redundant.
$adSpaceCorrect = !empty($payload->adSpaces) && is_array($payload->adSpaces);
if ($adSpaceCorrect)
foreach($payload->adSpaces as $adSpace)
if(!is_string($adSpace))
$dataStatus.='Ad Spaces contains a non-string value.';
$adSpaceCorrect=false;
break;
1
also, there's a typo inif(!is_string(adSpace)){
â hjpotter92
Jan 5 at 18:04
@hjpotter92 - Thanks for pointing that out!
â Occam's Razor
Jan 5 at 18:05
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
- The check for
count($payload->adSpaces)>0
is redundant because you already know it's a non-empty array as per$adSpaceCorrect
. - Once you correct the nested
if
s it becomes clear that the second$adSpaceCorrect=false;
is redundant.
$adSpaceCorrect = !empty($payload->adSpaces) && is_array($payload->adSpaces);
if ($adSpaceCorrect)
foreach($payload->adSpaces as $adSpace)
if(!is_string($adSpace))
$dataStatus.='Ad Spaces contains a non-string value.';
$adSpaceCorrect=false;
break;
1
also, there's a typo inif(!is_string(adSpace)){
â hjpotter92
Jan 5 at 18:04
@hjpotter92 - Thanks for pointing that out!
â Occam's Razor
Jan 5 at 18:05
add a comment |Â
up vote
0
down vote
accepted
- The check for
count($payload->adSpaces)>0
is redundant because you already know it's a non-empty array as per$adSpaceCorrect
. - Once you correct the nested
if
s it becomes clear that the second$adSpaceCorrect=false;
is redundant.
$adSpaceCorrect = !empty($payload->adSpaces) && is_array($payload->adSpaces);
if ($adSpaceCorrect)
foreach($payload->adSpaces as $adSpace)
if(!is_string($adSpace))
$dataStatus.='Ad Spaces contains a non-string value.';
$adSpaceCorrect=false;
break;
1
also, there's a typo inif(!is_string(adSpace)){
â hjpotter92
Jan 5 at 18:04
@hjpotter92 - Thanks for pointing that out!
â Occam's Razor
Jan 5 at 18:05
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
- The check for
count($payload->adSpaces)>0
is redundant because you already know it's a non-empty array as per$adSpaceCorrect
. - Once you correct the nested
if
s it becomes clear that the second$adSpaceCorrect=false;
is redundant.
$adSpaceCorrect = !empty($payload->adSpaces) && is_array($payload->adSpaces);
if ($adSpaceCorrect)
foreach($payload->adSpaces as $adSpace)
if(!is_string($adSpace))
$dataStatus.='Ad Spaces contains a non-string value.';
$adSpaceCorrect=false;
break;
- The check for
count($payload->adSpaces)>0
is redundant because you already know it's a non-empty array as per$adSpaceCorrect
. - Once you correct the nested
if
s it becomes clear that the second$adSpaceCorrect=false;
is redundant.
$adSpaceCorrect = !empty($payload->adSpaces) && is_array($payload->adSpaces);
if ($adSpaceCorrect)
foreach($payload->adSpaces as $adSpace)
if(!is_string($adSpace))
$dataStatus.='Ad Spaces contains a non-string value.';
$adSpaceCorrect=false;
break;
edited Jan 5 at 18:05
answered Jan 5 at 17:42
Occam's Razor
1,982513
1,982513
1
also, there's a typo inif(!is_string(adSpace)){
â hjpotter92
Jan 5 at 18:04
@hjpotter92 - Thanks for pointing that out!
â Occam's Razor
Jan 5 at 18:05
add a comment |Â
1
also, there's a typo inif(!is_string(adSpace)){
â hjpotter92
Jan 5 at 18:04
@hjpotter92 - Thanks for pointing that out!
â Occam's Razor
Jan 5 at 18:05
1
1
also, there's a typo in
if(!is_string(adSpace)){
â hjpotter92
Jan 5 at 18:04
also, there's a typo in
if(!is_string(adSpace)){
â hjpotter92
Jan 5 at 18:04
@hjpotter92 - Thanks for pointing that out!
â Occam's Razor
Jan 5 at 18:05
@hjpotter92 - Thanks for pointing that out!
â Occam's Razor
Jan 5 at 18:05
add a comment |Â
What did the interviewer ask?
â Mast
Jan 5 at 17:39
What exactly do you mean by "easier"? easier to read? easier to maintain? Also, Your title is too common a request to be appropriate for this site. What task does this code accomplish? Please tell us, and also make that the title of the question. "State what your code does in your title, not your main concerns about it.". Please read How to Ask.
â Sam Onela
Jan 5 at 17:49
@SamOnela - It's evident to me that he's not a native English speaker, maybe he doesn't know a better word than "easy." Also, he's new here, perhaps you could point out the Edit button and explain that's how he is to update his title to state the function of the code - although, if the code was given to him in an interview he may not know the function of it.
â Occam's Razor
Jan 5 at 18:13
Yeah I should have included
[edit]
in my comment; actually this code looks like a stub until the other variables are declared/defined here.... which makes this question off-topic...â Sam Onela
Jan 5 at 19:29