7 kyu
Add property to every object in array
14,920 of 15,019Clarity
Loading description...
Fundamentals
Arrays
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.
по следам моих ошибок: изменять нужно только questions, какой questions будет дан - неизвестно, поэтому копировать из примера не нужно.
I think testing framework had some mayor updates and now it's breaking
usersAnswer
is not a pre-defined variable, it's meant to be taken literally as astring
. this kata has a bad design, but it is running correctly.This comment has been hidden.
You should modify the array in-place and not create a new one.
This comment has been hidden.
8 kyu level
Waste of time thanks to poor description.
What is wrong with description?
Terrible kata. Really simple but the description is not comprehensive enough
what a bad kata.... the instructions are not clear!
After you write your function to solve this kata, you have to actually call your function otherwise it will not pass the test.
That's a problem with your code, not a kata issue. And probably it's a duplicate of this
Note that nowhere it says write a function.
True, I guess it is just a much different description from every other kata I had experienced so far. Thank you for the update.
This comment has been hidden.
This comment has been hidden.
Thanks to rsschool_Legat14 for answer below: If you have a problem with this kata and have no idea, why, you must know, that after you write a function you also must call it. It doesn't runs automatically.
Can anyone help me to understand what this Error message means: Unspecified AssertionError
I am doing this task and my code work in browser console, it returns required result. But somehow it doesn't work properly in this test and I can't understand what this Error message means and what I should correct.
Thanks to rsschool_Legat14 for answer below: If you have a problem with this kata and have no idea, why, you must know, that after you write a function you also must call it. It doesn't runs automatically.
Thank you for your reply. I want to mention that I know that a function must be called to it to work. But in all previous katas, that I solved there never was such requirement. All functions were called automatically. So when it wasn't mentioned in the description or Sample test of your task, I haven't assumed that in your kata there was a need to add a code to call a function. I only found out about it, when a read a comments in this disscusion area.
kata like shit
IDK what went wrong, but after I gave up and looked the solutions up, there it was, my original solution. It passed the tests, but then just would not submit.
It's a terrible task. I was never able to pass the test, because in the end I had to write question = question.(your solution). The author of everything bad
Very Nice
If you have a problem with this kata and have no idea, why, you must know, that after you write a function you also must call it. It doesn't runs automatically.
It's kinda weird to solve this kata because you don't write any function.
like (y)
This comment has been hidden.
var questions = [ { question: "What's the currency of the USA?", choices: ['US dollar', 'Ruble', 'Horses', 'Gold'], corAnswer: 0, }, { question: 'Where was the American Declaration of Independence signed?', choices: ['Philadelphia', 'At the bottom', "Frankie's Pub", 'China'], corAnswer: 0, }, ];
const addNewProperty = (array, property, value) => array.map(object => ({ ...object, [property]: value }))
questions = addNewProperty(questions, 'usersAnswer', null)
console.log(questions);
guys i got error here when am submitting my code in the time tht it should work perfectly i got errors said
The number of properties is not what is expected
andThe length of the array should not be modified
any helpFrom the description:
The questions array is already defined for you and is not the same as the one in the example.
Drop thequestions
array and it will pass.@clarity thank you alot i didnt read the last line omg
I passed all tests but I can't submit
I disabled adblock and I was able to submit.
this test is so bad fixing the sentence
pretty lame kata; because you don't actually write a function which is then automatically applied. You pretend as if you really have a given var - questions which is an array. I did everything right, but couldn't pass tests, just because I expected my function to be run on a whatever var automatically - this approach us quite common for the codewars kata. So please review your Kata and make amendments. because the task is ridiculously easy but not with the tests
var questions = [{ question: "What's the currency of the USA?", choices: ["US dollar","Cats", "Ruble", "Horse", "Gold"], corAnswer: 0, }, { question: "Where was the American Declaration of Independence signed?", choices: ["Philadelphia","California", "At the bottom", "Frankie pub", "China"], corAnswer: 0, }];
function looper(arr) { for (var i = 0; i < arr.length; i++) { questions[i].userAnswer = null; } }
looper(questions);
I used the code above....which should be correct, yet your test considers it wrong....why?
Here's why I think you got it wrong
I don't believe the code kata inputs the questions array into any function.
Sorry for the later reply. JosephBNolan it's usersAnswer not userAnswer.
make sure that you actually call the funciton with questions in your solution box.
Ex; function x( array){....}; x(questions);
i had a similar problem and after i put that after my function in the solution box it worked
very very easy =(
My solution was accepted, even though on second thought I believe it soudln't have: I generated a new array with the added property, that i didn't re-assign to the questions variable.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
I guess making the pre-defined array similar to the one in the examples was a bad idea. Now I have changed that, which broke the solutions that pasted the array from the example. I think the issue is resolved now. Let me know if it still persists or if there are other issues.
For those who reported minor issues: if you think they were resolved, could you mark the kata as ready?
Since my solution really shouldn't work, I suggest also checking question.hasOwnProperty("usersAnswer")
Done!
tests pass anyway
That's weird, I only now noticed that the name of the property is not the same. Anyway, I've updated the tests and now this solution doesn't work anymore.
Would be nicer to have a pre-defined function body in the result section and some test cases already defined.
Also, the test cases should check for === null instead of = 'null', as that would match the String 'null' as well.
The test cases should iterate over the entire questions array to validate that the usersAnswer property is set, instead of using the random index.
Would be a good idea to test some edge cases, like an empty array.
Thanks for the comment! I've updated the test case and put one as an example. Since the solution does not necessarily require a function I didn't define anything in the results section. Regarding the edge cases, don't the current ones already test for an empty array?
Looks good now!