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.
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"
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
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
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:
defyour_function(l):
print(l) # <--- this print statement will show you the input, here 'l', in # the console when you run teststhe_rest_of_your_code...
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.
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
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.
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
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.
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.
Yes, the author means that these are string
I mean strings in Array
Ah, I got it mixed up. Thank you!
The first argument is the string, the second one is the prefix:
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
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
[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.This comment is hidden because it contains spoiler information about the solution
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
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.
Because you're escaping the backslash like that and you should use a line-break instead:
'\n'
See the sample test:
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
love your simpson
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.
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...