Ad
  • Custom User Avatar

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

  • Custom User Avatar

    Ok, thank you all, I will try to take my time with better understanding my solution and how to improve it.

  • Custom User Avatar

    Your reasoning is more or less okay, the problem is with the test you think to be failing. When I try to run your solution, I see that it fails following test case:

    recipe:  { cream: 200, flour: 300, sugar: 150, milk: 100, oil: 100 }
    available:  { sugar: 1700, flour: 20000, milk: 20000, oil: 30000, cream: 5000 }
    

    Your solution has a bug which fails for the input above, but it works for the input which you showed and I am not sure what exactly leads you to the conclusion that your solution fails your test, and not the one I found.

  • Custom User Avatar

    You should use console.log to print inputs, and probably some other variables too. This way you'll know exactly which test case failed.

  • Custom User Avatar

    @hobovsky Thank you for reply. Could you give me example what other test my solution is failing against ?
    When I comment out this one test case:

    // recipe = {flour: 500, sugar: 200, eggs: 1};
    // available = {flour: 1200, sugar: 1200, eggs: 5, milk: 200};
    // assert.equal(cakes(recipe, available), 11);

    then assertions pass.

    Also would you tell me if there is gap or wrong logic in the way I explained this to work ?

  • Custom User Avatar

    Your solution fails other test than you showed above.
    Your solution has a bug, it is not a kata issue.

  • Custom User Avatar

    I passed all exampe tests and random tests besides this one(the one random test I append to test suite in example tests):

    recipe = {flour: 500, sugar: 200, eggs: 1};
    available = {flour: 1200, sugar: 1200, eggs: 5, milk: 200};
    assert.equal(cakes(recipe, available), 11);
    

    Based on how logically it would work I would expect having the smaller ratio between same igredient from available divided same ingredient ie. flour in recipe having 500 and flour in available having 1200. I understand it as 1200 / 500 = 2.

    Can someone please help me better undestand if this kata random test is correctly done ?

  • Custom User Avatar

    I passed all exampe tests and random tests besides this one(the one random test I append to test suite in example tests):

    recipe = {flour: 500, sugar: 200, eggs: 1};
    available = {flour: 1200, sugar: 1200, eggs: 5, milk: 200};
    assert.equal(cakes(recipe, available), 11);
    

    Based on how logically it would work I would expect having the smaller ratio between same igredient from available divided same ingredient ie. flour in recipe having 500 and flour in available having 1200. I understand it as 1200 / 500 = 2.

  • Custom User Avatar

    I solved it with using replace with regexp. However I am still confused why there was error with toUpperCase function called. There is only string as input as I need to dig this deeper.

  • Custom User Avatar

    clean, clever and quite readable.

    Just wondering what Big O notation in terms of space and time your solution would be.
    I would guess that Big O notation in terms of time would be O(n*m), where n is size of input and m is size of markers.
    About Big O notation in terms of size complexity it would be just O(1), constant as no variables are explicitly declared in function ? Can someone please correct me ?