6 kyu

Multiply list by integer (with restrictions)

437 of 845suic
Description
Loading description...
Puzzles
Lists
Functional Programming
Restricted
  • Please sign in or sign up to leave a comment.
  • ChiefAffirmationOfficer Avatar

    On further experimentation, there are definitely JS test cases which expect the output to be -0 when both the multipland and multiplier are positive numbers.

    In one random test case, for example, n (the multiplicand) is 291 and the first integer in the array (the multiplier) is 0. The test is failing because it says that the result of that first multiplication is expected to be -0.

    If we could expect all such cases (where the multiplicand and multiplier are both positive) to result in a negative zero for some reason, then fine: we could work around it sensibly. But not all the test cases expect negative zero in this "positive times positive" scenario.

    Right now, this kata as described seems unsolvable in JavaScript. Perhaps the description needs updated if there is some implicit requirement for returning negative zero in certain conventionally-unexpected cases. But more likely, there is a bug in the test solution.

  • ChiefAffirmationOfficer Avatar

    Why are we still getting -0 in the "expected" results in this kata, particularly in JavaScript?

    It's not even conventionally possible to check for -0 in JavaScript using operators, Math.sign(), or the rest of the Math library, as far as I can tell. You can't even use right-shift to find that.

    (I can find two ways to do it, but they are both highly obscure and one of them appears to be undocumented. I will mention them in a comment below with a spoiler tag for those interested.)

  • CaHudson94 Avatar

    Honestly it feels like the point of this is to not use multiplication and iteration over what you are given, but that is just my interpritation. This is a great Kata if you work under that idea but it seems most others went about it as finding built ins or other functions to get around the restrictions rather than figruing out the math solution.

  • o2001 Avatar

    I feel like banning the star operator makes sense in the Python translation but not JS. In Python, you can still multiply in a functional way without using the asterisk. In JS, not so much; there is nothing functional about the approach you'd have to take there.

  • maxxich Avatar

    Expected: '[-0, -357, 714, -1071, 1428, 1785, -2142, -2499, -2856, 3213, -3570, -3927, 4284, 4641, 4998, -5355, 5712, 6069, 6426, -6783, 7140, 7497, 7854, 8211, -8568, -8925, 9282, -9639, -9996, -10353, 10710, 11067, 11424, 11781, -12138, 12495, -12852, -13209, 13566, 13923, 14280, -14637, 14994, -15351]', instead got: '[0, -357, 714, -1071, 1428, 1785, -2142, -2499, -2856, 3213, -3570, -3927, 4284, 4641, 4998, -5355, 5712, 6069, 6426, -6783, 7140, 7497, 7854, 8211, -8568, -8925, 9282, -9639, -9996, -10353, 10710, 11067, 11424, 11781, -12138, 12495, -12852, -13209, 13566, 13923, 14280, -14637, 14994, -15351]'

    It seems there is still a problem with negative zero.

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • tonylicoding Avatar

    This comment has been hidden.

  • timaliev Avatar

    Expected: '[-0, -618, -1236, 1854, -2472, 3090, 3708, -4326, 4944, -5562, 6180, 6798, -7416, -8034, 8652, 9270, -9888, 10506, 11124, 11742, -12360, 12978, 13596]', instead got: '[0, -618, -1236, 1854, -2472, 3090, 3708, -4326, 4944, -5562, 6180, 6798, -7416, -8034, 8652, 9270, -9888, 10506, 11124, 11742, -12360, 12978, 13596]'

    Realy '-0' for multiplication result is correct? What did I missed?

  • gzngzn Avatar

    Hello! Can you answer me, how happened this? -938 * 0 === 0 And -874 * 0 === -1 What the difference?

  • user5504489 Avatar

    In JavaScript version,It seems that only positive integers are tested. How about negative integers? Some solutions might not be accepted. Like this: multiply(-1,[1,2,3]) Some solutions use "while",and might lead to "dead cycle".

  • WrightCode Avatar

    The l (list) array appears to be surrounded by quotation marks, is this the reason that when I try to convert it to a string I end up with blackslashes with my results?

  • matt c Avatar

    javascript translation created.

  • gabbek Avatar

    Lovely kata, thank you, suic!

  • user5036852 Avatar

    My first solved python-kata! :-)

  • snormandeau Avatar

    This comment has been hidden.