Ad
  • Custom User Avatar

    Ternary operator to return true or false is unnecessary.

  • Custom User Avatar
    count_smileys([5]);
    

    This case will return 1, instead of 0.

    count_smileys([':))']);
    

    This case will return 1, instead of 0.

  • Custom User Avatar
  • Custom User Avatar
    1. The line with "$string;" does not do anything.
    2. $startString count be $stringWithoutFirstChar / $endString could be $stringWithoutLastChar
    3. A lot of assigns. Sometimes it is good to have clear variables. Sometimes the code is still legible without assigns.
    4. Do not keep debug into your final code.
  • Custom User Avatar
    1. The line "$string;" does not do anything.
    2. You do not need to store every result of function calls into variables (especially when you only want to return that result).
    3. Do not keep the debug into your final code.
  • Custom User Avatar
    1. Regular expressions are best fitted to situations where string functions usage would be complex. There is a cost to: (1) parse the regular expression; (2) compile the regular expression; and (3) execute the regular exmpression.
    2. You can avoid constructions like "if (condition) { return true; } else { return false; }" replacing it by "return condition;"
    3. Do not keep the debug in your final code.
  • Custom User Avatar
    1. You do not need to add your points to the array of class points because, mathematically:
      a. if the avg of the class is lower than your points, it will continue lower if you include your points.
      b. if the avg of the class is equal your points, it will continue equal if you include your points.
      c. if the avg of the class is greather than your points, it will continue greather if you include your points.

    2. You can avoid constructions like "if (condition) { return true; } else { return false; }" just by replacing it by "return condition;"

    3. Do not keep the debug on the final code.

  • Custom User Avatar

    Do not keep the debug in the final code.

  • Custom User Avatar
    1. Do not keep the var_dump in the final code.
    2. Initialize the variable to avoid warnings/notices.
    3. Use better variable names.