3 ms·
>I had no idea what that might do. No expectations at all. Really? How is it any different than: "Hello".repeat(3).join(",");
by coldtea 12y ago
>I had no idea what that might do. No expectations at all.
Really? How is it any different than: "Hello".repeat(3).join(",");
- coldpie 12y agoMostly because the order of operations is unclear. I read it as producing "HelloHelloHello, ". That is, repeat the previous thing three times and then concatenate that with the string ", ". It's surprising to me that "repeat" results in a new object with new semantics.
- ilitirit 12y agoDepends on the language I guess. I read it as "repeat the string Hello thrice and then add a comma and space". It's not really clear that "repeat" returns a list. A C# equivalent would be: String.Join(", ", Enumerable.Repeat("Hello", 3)) Here it's easier to see that Repeat returns an Enumerable object. Using an Extension Method, it's easy to see how someone could mistake the output: https://ideone.com/DuIvZN https://ideone.com/DuIvZN