Daily Challenge #10

Number 10 already. Not always easy to think of something or find something but it is fun to do.

  • How does this work?
  • Can you do this in another way?
  • What is special here?

8 Likes

Trying to use my tiny brain on this, :laughing:

2 Likes

@peter, I got it :star_struck:


It checks the number of “x” and “o” in the string, if one of them is found, it increments their respective counter variable by 1.
Then, return true if the number of “x” and “o” are the same; else false


Am I right? :smile:

1 Like

I did it…
Here is an alternative method.

2 Likes

You guys are quick. Good job. But you still have to answer this question?

3 Likes

here comes the mood spoiler

what’s special?
it really doesn’t matter if it is upper case or lower case, it convert every character to downcase and then proceed

1 Like

Nope, that is not the special feature. :sunglasses:

I think special thing is you set string not Boolean in result in If Then Else

1 Like

Nope, that is not the special feature. :sunglasses:

1 Like

Recursion :sweat_smile:

3 Likes

Flagging as duplicate. :joy:

6 Likes

I think the special feature is that it only counts appearance of ‘x’ and ‘o’
:thinking:

I don’t see anything “special”, per se, but here are some oddities I noticed:

  • String “true” and “false”, instead of booleans. Weird choice.
  • String and Maths equalities, instead of logic equalities.
  • Extension of point 1: if the output were to be boolean, then you could simply return “x==o”. That would be more optimized, even if no significant performance gains are achieved.
1 Like

Shall i tell you?

1 Like

Maybe it is for Tic-Tac-Toe game? So you can count X and O letters and decide who will play at next turn. :thinking:

3 Likes

Nope, but i like your fantasy. :grin:

4 Likes

because the variable holds numerical value:wink:

1 Like

Logical operators work on everything.

1 Like

it can be considered good practice if using parent type is same as the child’s, although no fast and hard rule, developers have freedom:slight_smile:


Peter, is it really a feature??:thinking::crazy_face:

I prefer to mix types… Yeah I know. It’s a nightmare for some. :grimacing:

1 Like