7 kyu

Add property to every object in array

14,920 of 15,019Clarity
Description
Loading description...
Fundamentals
Arrays
  • Please sign in or sign up to leave a comment.
  • rsschool_097c0bcabadd9611 Avatar

    по следам моих ошибок: изменять нужно только questions, какой questions будет дан - неизвестно, поэтому копировать из примера не нужно.

  • Javatlacati Avatar

    I think testing framework had some mayor updates and now it's breaking

    ReferenceError: usersAnswer is not defined
        at Object.<anonymous> (/workspace/node/test.js:59:12)
        at Module._compile (node:internal/modules/cjs/loader:1159:14)
        at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
        at Module.load (node:internal/modules/cjs/loader:1037:32)
        at Module._load (node:internal/modules/cjs/loader:878:12)
        at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
        at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
        at async Promise.all (index 0)
        at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
        at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)
        at async formattedImport (/workspace/node/node_modules/.pnpm/mocha@10.2.0/node_modules/mocha/lib/nodejs/esm-utils.js:9:14)
        at async exports.requireOrImport (/workspace/node/node_modules/.pnpm/mocha@10.2.0/node_modules/mocha/lib/nodejs/esm-utils.js:42:28)
        at async exports.loadFilesAsync (/workspace/node/node_modules/.pnpm/mocha@10.2.0/node_modules/mocha/lib/nodejs/esm-utils.js:100:20)
        at async singleRun (/workspace/node/node_modules/.pnpm/mocha@10.2.0/node_modules/mocha/lib/cli/run-helpers.js:125:3)
        at async exports.handler (/workspace/node/node_modules/.pnpm/mocha@10.2.0/node_modules/mocha/lib/cli/run.js:370:5)
    
  • rsschool_07c162d9030b6fe7 Avatar

    This comment has been hidden.

  • rsschool_07c162d9030b6fe7 Avatar

    This comment has been hidden.

  • EndyPlus Avatar

    8 kyu level

  • theflyingpotato Avatar

    Waste of time thanks to poor description.

  • FinzyPHINZY Avatar

    Terrible kata. Really simple but the description is not comprehensive enough

  • Milo.Co Avatar

    what a bad kata.... the instructions are not clear!

  • toppirl Avatar

    After you write your function to solve this kata, you have to actually call your function otherwise it will not pass the test.

  • Andrea Vicari Avatar

    This comment has been hidden.

  • rsschool_b80f69045c29987d Avatar

    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.

  • user9397914 Avatar

    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.

  • Underdante Avatar

    kata like shit

  • Alekole Avatar

    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.

  • weltkind6 Avatar

    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

  • rsschool_Legat14 Avatar

    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.

  • farhanaditya Avatar

    It's kinda weird to solve this kata because you don't write any function.

  • SaadaniMohamedAmine Avatar

    This comment has been hidden.

  • Faker88Si Avatar

    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 and The length of the array should not be modified any help

  • djorgeivan Avatar

    I passed all tests but I can't submit

  • sipubot Avatar

    this test is so bad fixing the sentence

  • mickeyboston Avatar

    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

  • JosephBNolan Avatar

    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?

  • Keleborn Avatar

    very very easy =(

  • mochachocolatte Avatar

    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.

  • dmtri Avatar

    This comment has been hidden.

  • erollroguel Avatar

    This comment has been hidden.

  • Clarity Avatar

    For those who reported minor issues: if you think they were resolved, could you mark the kata as ready?

  • MCL Avatar

    Since my solution really shouldn't work, I suggest also checking question.hasOwnProperty("usersAnswer")

  • stefan1 Avatar

    tests pass anyway

  • maartenhaubrich Avatar

    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.