7 kyu
Friend or Foe?
91,829 of 207,221Aweson1
Loading description...
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
This comment has been hidden.
This comment has been hidden.
I copied and pasted your code and it worked.
Test Results: Basic tests Testing for fixed tests TypeError: friends.reduce is not a function at friend (test.js:4:26) at Context. (test.js:23:22) at process.processImmediate (node:internal/timers:471:21) Completed in 1ms
Have you somehow, messed up the sample tests? Backup your code, click reset, paste it and try again.
Code works for me as well, and you seem to have passed all tests, so I'll mark this as resolved.
No random tests in TS
I am solving it in C. It passes test but when i try attempt it gives error in random tests. What could be the problem?
We cannot tell without knowing what your solution is.
This comment has been hidden.
Please see documentation how to use code formatting.
This comment has been hidden.
you forgot the
c
language tag after the 3 backticks:```c
.also please include the necessary headers for easier copy pasting.think more carefully about this line: what does it achieve ? are you sure this index is still within the array ?
In Python 3.11, even if the code is correct, it seems to produce an error stating: Traceback (most recent call last): File "/workspace/default/tests.py", line 2, in from solution import friend ImportError: cannot import name 'friend' from 'solution' (/workspace/default/solution.py)
See also this article.
Your code is not a valid solution for Codewars kata. It's not a kata issue.
The description says the input and output are lists, but the examples are shown in set notation. It could be helpful to edit this for consistency.
C++ fork:
Please, review and approve/reject
Merged.
Alright, this kata has different requirements depending on the language you’re using. For example, some languages like C++ expect the output to be
[""]
(an empty string inside an array (why on Earth someone would even?....)), while others like C expect just an empty array[]
.Someone recently fixed this issue, but now we’re left with a new problem: in some languages, the task and its description no longer match.
Any ideas on how we can fix this with the least amount of headaches?
UPD: Okay, I went through all languages except Factor, because I don't know Factor, and it appears that this strange thing happens only in C++. So fixing it in C++ would probably be the best course of action.
Done.
The F# version has a bug in the test that refers to the function as "friend", but the boilerplate code uses the name "friendOrFoe". I had to modify the test before I was allowed to submit.
Fixed (you need to reset the trainer to see the fix).
Empty result case is unclear.
Should say:
If there are no friends retun an empty list.
And also add a test case:
Otherwise, thanks.
fixed
At least in JS, Python, and Haskell ( and quite possibly in most or all languages ), an empty list is expected, instead of a list of a single empty name.
fixed
I am a novice at coding. I am trying to work out what the array is called to right some code around it.
Since the first element is String. I am going to assume it is names?
I cannot for the life of me get it to ConsoleWriteLine(names). is the console log function not operational? So not sure if any code I write is correct.
See if this article helps. You can also visit Codewars Discord and ask any questions you have in
#beginners
, or in#help-solve
channels.Console.WriteLine
is fully operational on Codewars, and it should work if used correctly.You should use it inside the method, and you don't need brackets around "names".
Ok let me have another look. Thank you
Should do the trick. But make sure to return something that the function expects (you could just "return names" to avoid errors).
this is what I have tried in many cases. This is why I have been confussed. I have not tried to return just names. Without the log. I will try this out.
thank you
such a simple task However I still have a cannot convert type void error.
Here's a basic template:
aahhah I sat for 30 minutes and couldn't figure out why my code wasn't working until I noticed that I hadn't created an empty list.
Me toooo!
Testing for fixed tests Log [ 'Ryan', 'Mark' ] expected undefined to deeply equal [ 'Ryan', 'Mark' ] ...what did I do wrong?
This comment has been hidden.
Thank you
For C: why argyment is const and need to be modified? But function returs void?
the input is an array of pointers to
const char
. it is not an array ofconst
pointers, so you can modify it. the function returnsvoid
because you are supposed to mutate the array in-place instead of returning a brand new arrayFor this question i have written the code but for this test case
Testing for Ivan, Dick: expected [] to deeply equal [ 'Ivan', 'Dick' ]
i am getting this but here as the two names have same length so we must return empty array and for this part i have written the logic so why my code is getting failed for this test case
Where do you see that if the two names have the same length you should return an empty array? Read the description again, if the names have a length of 4, then they are your friends and they should be in the output array.
It's so satisfating when aproved screen appears! :)
it's a good sensation after a day of working as a part of day challanges to solve one kata and you feel like liberated from the rest of the day.
The instructions of the test were'nt completely clear
You should explain this in more detail if you expect to have any impact.
no answer, closing
This comment has been hidden.
This comment has been hidden.
Thank you, that's a helpful mapping (no pun intended)
This comment has been hidden.
No, numbers have been removed from the tests, see here: https://www.codewars.com/kata/55b42574ff091733d900002f/discuss#5f85d45185311d00198380d7
So do I understand it correctly, that we also need to provide x, the list of names?
No, the list of names is already given as a parameter of the function. Read this on how to train on CW
it is not specified what a 'name' is.
"abcd1234"
has 4 letters in it. most languages seem to accept a solution that simply filter out strings whose length is not4
Agree, that part was ambiguous. I assumed length must equal 4 characters and all of the characters had to be case insensitive letters. The test cases and description for this problem should be more explicit.
resolved the ambiguity by specifying that the input strings will only comprise letters
C translation doesn't check for "letters" in solutions as per the description; any string of length 4 is accepted.
not specific to the C version (and you know it, since you approved another translation that does exactly the same...)
ef
there is a missing argument in line 9 when checking the code, because of this I can't complete the assignment. TypeError: friend() missing 1 required positional argument: 'x'
when I ran your code, I did not get the
TypeError
, instead I just saw that it fails on certain tests.this is not a kata issue. over
67K
coders have solved this in Python.Traceback (most recent call last): File "/workspace/default/tests.py", line 3, in import solution.friend ModuleNotFoundError: No module named 'solution.friend'; 'solution' is not a package
Iam Getting This Error Then How Can I Resolve This Error This Is not My Mistake,,,My Programm Is Working Fine
A couple things:
For more details, check out this tutorial.
No random tests in C#
added
This comment has been hidden.
This comment has been hidden.
Scala translation
LGTM, Approved!!!
This comment has been hidden.
Please don't post solutions in Discourse.
This comment has been hidden.
This section isn't for sharing solutions, you have Solutions tab for that.
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting#post-discourse
About the error it shows, read it:
The function's argument was
friends
and your wrotefriend.length
that's why you get that error. There are other problems with that code, but because you already have a working solution, I'm not going to explain them.This comment has been hidden.
This comment has been hidden.
this should be a 8 kyu!
This comment has been hidden.
From the instructions it is not clear, that "4 letters" mean 4 characters long, including numbers and repeted letters.
raised as an issue here
This comment has been hidden.
funny ^-^
This comment has been hidden.
Hi @H1kmetH4SH and welcome to Codewars!
You must return your solution, rather than
print
it - if you are new to the site you can read this helpful document Solving katas which will explain the most common early mistakes people make.Also here is a useful link for Troubleshooting your solutions
Your current code looks OK to me, you just replace
print(realfriends)
withreturn realfriends
- that should work.Thanks so much <3
This comment has been hidden.
kata hint != kata suggestion (also use spoiler flag please
I think the test should also include "Abc1", which should not count as a friend.
Wtf?
Testing for Ryan, Arnold, Dick, Max, Chris, Bart, JoJo, Kyle, Alex, Bruce: expected [ 'Ryan', 'Dick', 'Bart', 'JoJo', 'Alex', shuffle: [Function] ] to deeply equal [ 'Ryan', 'Dick', 'Bart', 'JoJo', 'Kyle', 'Alex', shuffle: [Function] ]
This comment has been hidden.
This comment has been hidden.
should be a 8 kyu honestly.
This comment has been hidden.
Shouldn't the test weed out strings of numbers like "2222" as well an nonsense words?
Which language?
I agree with @salisburysteak.
Suggested test cases for Javascript:
assert.deepEqual(friend(["Ryan", "Kieran", "Ma#k"]), ["Ryan"])
assert.deepEqual(friend(["Ryan", "Kieran", "2222"]), ["Ryan"])
raising a more general issue about the unclear specifications: here
This comment has been hidden.
...and?
don't post solutions in the discourses pages. They are already visible in the solutions pages. Or if you have a qeustion, don't forget it in your message.......
This comment has been hidden.
Try to print your variables at different parts of your program. I suspect that you might think that
x[0]
is something that it isn't.I spent a lot of time to solve this kata. I thought that the array can contain a number of four characters, and i need to first remove all the numbers from the array, and than filter out the name strings already.
that`s a good one
C translation (author gone)
Approved
This comment has been hidden.
This comment has been hidden.
Good kata for practicing array filters. Though the numbers in the test samples makes it a bit confusing even if they're just strings.
you have '123' in test case, but you don't have '1234' or '12k3'(string len = 4 with digits and letters)so the code of people who didn't even think to check it, works faster than with this logical check
It sucks. The numbers in Sample Tests are only confusing. Okay, 4 letters = our friend. What if it's 4 digits as a string of "1234"? Accordingly it is logical to arrange check and throw out first all the numbers in the form of strings from the array, and then filter the desired strings by number of characters.
This comment has been hidden.
!=
is not the problemyou are iterating through the
friends
list, and within the loop, removing items, which means that all items aren't looped throughlog the value of
item
before the if statementbetter to use another list/algorithm
This comment has been hidden.
Hello and welcome. Please do not post code without the spoiler tag, otherwise everyone can see it. I have added the tag to your comment for you.
Your function should return the new list, not print it to the console. Also, why are you using a fixed list instead of the function's argument? Please read this: https://docs.codewars.com/training/troubleshooting
The test code will call the pre-named function, so you'll want to start with what is provided (a function name) and
return
the results.This comment has been hidden.
accessing an element in a list/string/tuple is done with
[]
not()
. the latter is used for function callswhat is this below ?
/workspace/node/test.js:30
SyntaxError: Unexpected end of input at wrapSafe (internal/modules/cjs/loader.js:915:16) at Module._compile (internal/modules/cjs/loader.js:963:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Module.require (internal/modules/cjs/loader.js:887:19) at require (internal/modules/cjs/helpers.js:74:18) at Object.exports.requireOrImport (/workspace/node/node_modules/.pnpm/mocha@8.3.0/node_modules/mocha/lib/esm-utils.js:42:12) at Object.exports.loadFilesAsync (/workspace/node/node_modules/.pnpm/mocha@8.3.0/node_modules/mocha/lib/esm-utils.js:55:34) at Mocha.loadFilesAsync (/workspace/node/node_modules/.pnpm/mocha@8.3.0/node_modules/mocha/lib/mocha.js:431:19) at singleRun (/workspace/node/node_modules/.pnpm/mocha@8.3.0/node_modules/mocha/lib/cli/run-helpers.js:125:15) at exports.runMocha (/workspace/node/node_modules/.pnpm/mocha@8.3.0/node_modules/mocha/lib/cli/run-helpers.js:190:10) at Object.exports.handler (/workspace/node/node_modules/.pnpm/mocha@8.3.0/node_modules/mocha/lib/cli/run.js:362:11) at /workspace/node/node_modules/.pnpm/yargs@16.2.0/node_modules/yargs/build/index.cjs:443:71
An error message, as it says, due to a syntax error, the compiler/interpreter finds the end of code while it should not. Most probably a bug in your code. Always say which language you're using (I guess JavaScript).
Thanks I found what i was doing wrong here.
Some tests are susceptible to mutation of input arguments and fail if your solution changes input objects passed to it. If the kata does not explicitly ask you to modify input arguments, make sure you do not do it. If you find a kata that fails when input is mutated by your solution, raise it as an issue (see here).
In general it's a bad practice to mutate the input. In some katas it doesn't make a problem, but it does in others. If you have weird/ununderstandable results it's something to check out prioritarily.
This comment has been hidden.
Not a kata suggestion, please don't post solutions in Discourse. You can add all those comments in your own solution before clicking
Submit
button.(friend(["Ryan", "Kieran", "Mark",]), ["Ryan", "Mark"]) i am getting it exactly and yet it keeps saying " [] should equal ['Ryan', 'Mark'] " even though the list contains those 2, 4 letter works in the same order.
This comment has been hidden.
This comment has been hidden.
Not a kata issue at all. Why do you have 3 functions with same name and random stuff after them?
Write 1 function only, and don't print anything.
https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
I didn´t properly know the difference of console logging and returning the value, thanks for the link
I keep getting told that this test fails... what is
shuffle: [Function]
?Testing for JoJo, Boris, Omar, Nikola, Frank, Lisa, Tim, Bart, Claire, Kyle: expected [ 'JoJo', 'Omar', 'Lisa', 'Bart', shuffle: [Function] ] to deeply equal [ 'JoJo', 'Omar', 'Lisa', 'Bart', 'Kyle', shuffle: [Function] ]
I've just submitted my old solution and such messages do not pop up. I've doubt it has to do with the deprecancy of JS Node 8. version which has yet to be updated at that point of time when such question was raised. Now, considered resolved. Do raise another issue with proof if such cases occur again.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Mutating the list you're iterating through, makes you skip values. And please mark your post as having spoiler content next time.
Thank you so much, Sorry about the spolier thing. I did not know. I will delete my comment now so dnt bother others looking for answers.Cheers
This comment has been hidden.
How can you make it work for numbers?
my code run fine when i run it in console log but it keeps saying this" expected [] to deeply equal [ 'Ryan', 'Mark' ] " even though with have the same output
This comment has been hidden.
This comment has been hidden.
Mutating the list you're iterating through, makes you skip values.
This comment has been hidden.
Not a suggestion.
C# Test cases need random tests.
Should probably also have fixed tests with
added
This comment has been hidden.
What should be written if an empty string is supplied?
Julia translation
Crystal translation
Approved
For this think a logic of filtering the data and set a condition for the same that they want in test cases. As for this they need if length is equal to 4 then only it will match all the test cases.
kata hint != kata suggestion
This comment has been hidden.
Please, stop posting your solutions in kata's discourse, also, this is not a kata
Issue
. Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solutionI'm attempting this challenge with JavaScript in the browser console it works, but it fails the test says its undefined and I don't understand why. I figured I'd use filter to filter out those that are exactly 4 characters but it just throws a bunch of undefined back at me why?
Your function should return the result instead of printing it to the console. Please read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
Thanks for the reply I did find that yesterday and had a read, but I'm struggling to understand what it is I'm doing wrong. I am attempting to return it yet all I get is undefined so I'm none the wiser.
Without seeing your code, me neither. In the link it is explained how to post your code here, give it a try and make sure you mark your post as having spoiler content.
This comment has been hidden.
Where is the
return
keyword there? Try addingreturn result;
This comment has been hidden.
Just click "Attempt" instead of "Test"
thx bro
Please, mark your post as having spoiler content next time. I've changed the sample tests, click reset to see the new ones.
This comment has been hidden.
Not a kata issue, you use a var with the same name as the function. Use
let
to keep the scope (and probably it's not a best practice to name two different things the same).oh, thank you so much, sorry for the stupid error
Python: my solution can't pass some random tests but the solution passes a sample test with the same data succesfuly.
Example:
random tests error "['vEnd', 'YtVi'] should equal ['vEnd', 'YtVi', 'e7FL', 'ig75', 'i8pE']"
sample test "Test.assert_equals(friend(['vEnd', 'YtVi', 'e7FL', 'ig75', 'i8pE']), ['vEnd', 'YtVi'])" passes successfuly.
See the issue raised by me 3 months ago.
This comment has been hidden.
You're mutating the input array, and that changes the expected values too.
thanks
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
solved it... the exclamation mark of course changed the hash so it passed first but not later...
gNeeds a test case for names with 3 or less characters. You can pass this by looking for names < 5 characters when the description says exactly 4.
This comment has been hidden.
It's not an issue. Your code doesn't work for a list with length more than 3. Check the output on Codewars interpreter
looks like u solved it
Python: why are numbers present in the names? That makes the description about 4 letters confusing because the tests don't mind if they are letters or not. I'd suggest the numbers be removed from the tests.
fixed
In python, plenty of tests are failing because the expected and actual are reversed. Hence I couldn't submit my solution
Sample: ['RQWk', 'htGD', 'epmV', 'lIzS', 'cDYv', 'zWVg'] should equal ['0BLO', 'RQWk', 'Ee3S', 'htGD', 'epmV', 'lIzS', 'p9kz', 'cDYv', 'zWVg'] ['DBAa', 'NVoa', 'nXfZ'] should equal ['O9wR', 'DBAa', 'NVoa', 'Wh6n', 'Ju8G', 'nXfZ', '1PXt']
Worked fine on my end. Are you filtering by len()?
yes, i did use len()
actual
andexpected
aren't reversed, your code filters strings with numbers in it, and the control function isn't doing that.Should be 8 kyu in my view.
This comment has been hidden.
Not sure if you'll see this or not, but don't change a list while iterating over it. This can give unexpected results. Hopefully that helps :)
This comment has been hidden.
Then read this first. You're doing several things wrong there, for instance, your function
friend
is called in the tests with a list as argument. All your code should be inside it, unless you write another small function to decide if a name is a friend or not, but that function shouldn't befriend
OK, I understand now, did a few more katas and all was nice, thanks a lot for the answer ^^
Thanks for actually marking it as a question because it is one :-D
This comment has been hidden.
Because
<==
doesn't exist, try with<=
This comment has been hidden.
Java Translation
Need feedback and approval. Thank You :)
Applied some improvements and approved. Powered by katafix 🤖
Hi, whenever I try to submit my code, it says that there are errors, eventhough when I test each list separately it passes. help please
We can't help you with only that, use markdown formatting and mark your post as having spoiler content.
This comment has been hidden.
I don't understand the expected output. Example: "['Ryan', 'Mark', 'Ryan'] should equal ['Ryan']" All four of those names have four characters in them, why is the expected output only Ryan and not all three?
The first one isn't the input, it's what your function returned. Print the input to see what it was.
You can try console.log if JS or test it in Google Console. Try identify the input before and after your method filter. And you'll do this challenge. Have fun.
This comment has been hidden.
This comment has been hidden.
Please, don't post solutions on Discourse, it's forbidden.
This comment has been hidden.
Don't use global vars, they keep their value between tests. Also your code's logic is wrong.
:)))
This comment has been hidden.
So you remove n from the list, making it smaller so now iterator moves +1 index and starting a new iteration it moves another +1 index. So therefore if you have two back to back not len(4) values you are skipping the second one
Not a kata issue.
I think this should be 8 Kyu
This comment has been hidden.
The wording of this question states "letters" instead of "characters". but the tests are really checking for characters. The description should be ammended
Agreed-- my solution was more complex than was necessary because I was filtering out letters-- which, if numbers are allowed, should not have passed.
There should be a test where the name is under 4 letters long, like Joe or Ann.
Otherwise you can have false passes, given a friend has to have exactly 4 letters in their name.
In some languages there are tests like that, it seems C# tests are lacking.
Why doesn't it work on the platform but does in my local python interpreter (3.7.4)?? I copied the failed test onto it, and it works fine.
Instead of us guessing, why don't you post your code marking your post as having spoiler content?
This comment has been hidden.
Write print(y) in the line below your for loop line (above the if), you'll see you're skipping values.
Use this sample test to check it:
Thx, got it. Learned something new.
This comment has been hidden.
wrote the code in javascript, I used filter method in a line and got all the tests to pass
This comment has been hidden.
Mark your post as having spoiler content when it does (already did it for you this time). Write print(i) in the line below your for loop line (above the if), you'll see you're skipping values.
Use this sample test to check it:
This comment has been hidden.
In JavaScript, there are backslashes before single quotes in the test descriptions in the Basic Tests, like this:
I think it should be something like this:
That's because the tests use
assertSimilar
.assertDeepEquals
could be used instead, but the kata works.This comment has been hidden.
Input is a
list
not astr
:Regards,
suic
thanks I resolved this issue
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
this won't be done after 50,000+ JS completions
This comment has been hidden.
On the JS version, random test cases don't run and give an error because the initial 'friends' array is set to a constant variable. Random cases only resolved after I changed the keyword from const to let. Once changed, kata resolved fine. Is this my mistake or an issue with the JS version?
Test cases don't cover length < 4 names.
Haskell translation added :) ,review welcomed
This comment has been hidden.
This comment has been hidden.
Use spoiler flag next time, read this again:
Your code only tests length is less than 5 (you'll be pushing strings of length of 3, 2, etc. too). And what are you pushing in the results array? Look closer to other solutions, if they're there probably they're ok and your code isn't. Try to spot the differences.
This comment has been hidden.
This comment has been hidden.
Don't use the word return
@komek, your function should return the result.
Why doesn't the .remove() method work for this kata? I did an if statement inside a for loop instead of returning a new list. Should've worked, because it worked for the sample test. Also, the logic is sound because the kata specifically required filtering the list. What am I missing?
remove mutates the list, check if you're not skipping values like that, or if mutating the list changes the expected results.
If the list is going to be filtered, it's going to have to be mutated. I still don't understand why the test cases would not work. What's wrong with having a mutated list? The indexes stay the same?
That's not true, you could generate a new list instead of mutating the input value. In many languages where it exists, filter method returns a new array/list. Your problem could be one of these:
That's in general, I don't know if these apply to your case here. Without actually seeing your code I can't say if it's one of these or another problem.
This comment has been hidden.
Mark your post as having spoiler content when it does (already did it for you this time). Write
print(friend)
in the line below yourfor
loop line (above theif
), you'll see you're skipping values as I said. There are some other problems with your code, like trying to get the length of a number instead of the length of the string.This comment has been hidden.
Please mark your post as having spoiler content next time.
See your code again.
they didnt say it but you should return the answer
why does the output show: None should equal ['Ryan', 'Mark'], though my code seem to be worked well in IDE.
Probably you're printing the result instead of returning it.
Issue solved! Thanks!
Is the description phrase, "name has exactly 4 letters in it," supposed to imply that cases like "Name42" and "hi-hi" should be accepted as friends or not? They do contain exactly 4 letters, but the test cases don't really address strings that mix character types.
raised as an issue here
This comment has been hidden.
Maybe because it's wrong? Your list comprehension is mutating the array, skipping some of the elements, and gets filled up with
None
's in the process.PowerShell Translation Kumited! :)
Rejected, see remarks in translation
After solving it and seeing the solutions.. I'm easliy the dummest dude around for not thinking about a key function to this. But hey.. learning and enjoying so cheers!
its kind of difficult for me tho am new here.
This comment has been hidden.
print
andreturn
are not the same ;-)oh yeah thanks mate
This comment has been hidden.
Several reasons but one of them is it's not right to mutate a list where you're running a loop with it. You'll skip values like that. Try figuring out for yourself the other problems.
I have problems with random tests. For example: "Testing for Omar, Alex, James, Kyle, Bart, Max, Arnold, Dick, Ryan, Ivan, Claire, Nikola, Lisa, Bruce, JoJo, Chris, Rachel, Frank, Tim It should work for random inputs too - Expected: '[]', instead got: '['Omar', 'Alex', 'Kyle', 'Bart', 'Dick', 'Ryan', 'Ivan', 'Lisa', 'JoJo']'" . But the answer is ok, all names in answer have exactly four letters I'm new in JavaScript
You're mutating the input.
Thanks! It was that!
Hi guys!
I'm getting this error "None should equal ['Ryan', 'Mark']", but there's no such strings in my input. As well the test case doesn't contain this. My code works in my terminal and it's 100% correct. What can be the matter? Thanks in advance!
same as you
This comment has been hidden.
I had the same problem. Did you include a return statement? For me, it stemmed from not understanding how the testing is done. I had included a print statement to print the results. When I changed it to a RETURN statement, the error went away. The instructions say to write a program, but really, you're only writing a function and stopping there. Adding more will make the testing setup error out.
This comment has been hidden.
'looks like you've solved it'
['Kieran', 'Mark'] should equal ['Ryan', 'Mark'] what the heck ,why is it showing this error? there is no 'Ryan' in first list then how would it be in the filtered list..
This comment has been hidden.
You should return the answer. Also, please mark your comment as having spoiler content if you display the answer as people can cheat and look at your solution.
Right, sorry about that. It's just fiddle not showing the return value so I logged it in console. Once i put code in codewars interpretor, it just won't pass tests. I don't get it cas I even added regExp to clear out all the symbols and it still won't pass. I was checking the output of the function on jsfiddle and it's all seems to be fine. I would appreciate some explanatioin on how to solve this one.
I don't know too much about javascript. However, it seems like you are not understanding the question correctly. When you call the 'friend' function, you pass in 2 arguments: the origial list of people, and what looks like the correct answer. However, in the tests, you are only given the original list of people and they are a friend if the only have 4 letters in their name. For example, when calling the friend function, you should call it by
friend(["Jimm", "Cari", "aret", "truehdnviegkwgvke", "sixtyiscooooool"])
, instead of something likefriend(["Jimm", "Cari", "aret", "truehdnviegkwgvke", "sixtyiscooooool"], ["Jimm", "Cari", "aret"])
The second argument is used only to check that your answer is correct, and you will not be given it in the tests. Anyway, I hope this helped. Maybe you could re-read the question to understand it more. Good luck!!Thank you. Will read it more carefully next time.
This comment has been hidden.
This comment has been hidden.
Why early return? ;-)
oppss.. tks a lot for that ;)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
I'm new to Pythin, don't know what to do
Needs more detail as to what friends you want to check for. Confusing.
i am getting ugly face as output: too long to respond...
CW problem, not kata problem. Closing.
i getting output as ugly face since yesterday : error too long t respond.
I am putting in the "Best Answer" and it is giving me a compiling error. "Type string[] does not contain a defintion for "Where".
not an issue. Check for different version of the language you're trying to "fork".
This comment has been hidden.
Not a suggestion.
Thank for suggestion :D
No problem :D
This comment has been hidden.
You need to return your output and not print it to the console. All katas on this website work like this. Returning the value, means the value is retained from that function call; the value retained can be checked for equality against the expected answer. Printing to the console is hard to check for equality. "None" is the default value when nothing is returned.
You can add identation by following Markdown formatting.
Thank you dude it worked now !!
You're welcome :)
Some of the random tests are also erroneous. For instance:
Testing for Alex, James, Arnold, Frank, Bruce, JoJo It should work for random inputs too - Expected: '['JoJo']', instead got: '['Frank', 'Bruce', 'JoJo']'
This was the error i got. It didn't expect for "Alex" even though it's a 4 letter word.
I think there should be a test that tests if the parameter (names) is null. Else it wouldn't be best practice...
too late for that: kata is too old and tests aren't modifiable anymore.
This comment has been hidden.
The result should be in the order of the original array with non-four letter words removed. It should preserve the order of the original array. I'll keep this issue open since it should be mentioned in the description.
Done.
That says nothing about my relationship with non-four-letter names.
done.
Awesome Blossom
So cool kata, tnx!
Logic error in description: "If a name has 4 letters in it..." Every name with 5 letters has 4 letters in it, description should be "If a name has exactly 4 letters in it..."
done.
CoffeeScript translation kumited! Please Accept :D
This comment has been hidden.
You need to return your output and not print it to the console. All katas on this website work like this. Returning the value, means the value is retained from that function call; the value retained can be checked for equality against the expected answer. Printing to the console is hard to check for equality. "None" is the default value when nothing is returned.
Descr is OK.
Maybe add random tests?
This comment has been hidden.
if I understand your code you return on the first iteration returning an array containing just the item 'Mark'?
From what I can tell, you're manually typing in the input. Well this will work for the test case, (Although, like matt said, you're returning a list with just 'Mark') it would be best practice to have it iterate through the input, and return a list of all 4 letter names in that list.
The exercise was correct and easy to start
What is the issue, then?
Not an issue
Not great description. just calling a list x does not look pretty.
Changed; what about now?
Not an issue
The instructions of the test were'nt completely clear
Changed; what about now?
Resolved.
All your friends only have four letter (change to 'letters') in their name.
Changed; what about now?
Resolved
Really didn't understand what I was supposed to be doing.
Changed description; what about now?
Not an issue
I guess, there are some random tests should be added.
Which language?
Issue isn't descriptive enough
This comment has been hidden.
This comment has been hidden.
@Alex-ley: Mark your post as having spoiler content next time, please.
Translations in both JS and Ruby submitted, if you want to approve them :)
Also, consider that you have duplicated tests in Python and let me know if you might appreciate me adding random test cases to it :)