Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>I had no idea what that might do. No expectations at all.

Really? How is it any different than: "Hello".repeat(3).join(",");



Mostly 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.


Depends 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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: