Ad
  • Custom User Avatar

    They should not be thought of as Strings ( even if they are - what they really are is just an implementation detail ). Think of them as a three-valued Boolean. They are in a Class of their own.

    If you are familiar with Option types, you could also think of them as an Option Boolean, but that introduces unnecessary complexity.

  • Custom User Avatar

    Yes, the author means that these are string
    I mean strings in Array

  • Custom User Avatar

    Ah, I got it mixed up. Thank you!

  • Custom User Avatar

    The first argument is the string, the second one is the prefix:

    startsWith("nowai", "nowaisir"); // should return false, "nowai" doesn't start with "nowaisir"
    startsWith("hello", "HE") should return false, because the check should be case-sensitive
    startsWith("hello", "he") should return true, because "hello" starts with "he"
    
  • Custom User Avatar

    I don't get the part where in the instruction it says "startsWith("nowai", "nowaisir"); // should return false" then in later lines it says "i.e. startsWith("hello", "HE") should return false, whereas startsWith("hello", "he") should return true." Which statemetn is correct? The second one? Thank you in advance

  • Custom User Avatar

    Thank you so, so much for both your tips!!! The first one is super useful and the second one perfectly answers my question. Once again, thank you so much

  • Default User Avatar
    1. Regarding the "only right or wrong answers" part - in general you can always print the input which will help you debug any Codewars kata. In Python you can do this by adding:
    def your_function(l):
      print(l) # <--- this print statement will show you the input, here 'l', in 
      # the console when you run tests
      
      the_rest_of_your_code ...
    
    1. Regarding why your code is wrong: it's a nice approach, but re-read the kata description: "...but ignores any duplicate items". What you are currently doing is summing the input list as though it were a set (i.e. counting each element exactly once) when in fact you should be "dropping" the elements that appear more than once. For example, your code on [1, 1, 2, 2, 3] gives 1+2+3 when the expected answer is 3, since you should not include 1 (it appears more than once) or 2 (it appears more than once) at all.
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Hi, I am a bit confused about the input. What is the class type of Like or Dislike? Are they strings? Are they boolean like True or False? Thank you in advance

  • Custom User Avatar

    thank you - by any chance, do you know why '\n' doesn't lead to automatic next line and instead prints out '\n' in codewars code editor? In my Pycharm when I did '\n' it automatically printed 3*3 #s without '\n' printed.

  • Custom User Avatar

    Because you're escaping the backslash like that and you should use a line-break instead: '\n'

    See the sample test:

    test.assert_equals(generate_shape(3), '+++\n+++\n+++')
    
  • Custom User Avatar

    I'm struggling with printing single backslash. In my pycharm app it works fine when I put "\" but for some reason it doesn't work in codewars. Can someone explain what is going on? Thank you

  • Custom User Avatar
  • Custom User Avatar

    Thank you very much for your advice. They are very, very helpful. I will work on the easy questions first - once again thank you so much.

  • Custom User Avatar

    Your approach is too inefficient to pass this kata. The problem of the method you are using (in both codes you are providing; they are actually equivalent) is that for each item in the list, you need to make a complete loop over the list to get the value you are interested in. If the array has 10 elements, your code will have to make 10 * 10 operations. If the array has 1000 elements, then it will be 1000 * 1000, etc. It's easy to understand that this approach is extremely slow with large arrays. It's hard to give you a concrete answer without giving away the solution. Actually it is possible to solve this kata with only 2 * n operations (with n being the length of the array). Try to think how you could adapt your second code to do it. If you don't manage it, try to make some research with good keywords. In Python, there are some data structures available that almost do all the job for you.

  • Loading more items...