Implement a function pattern, which returns the following pattern for up to n number of rows. If n < 1 then it should return " " i.e. empty stri...
For further actions, you may consider blocking this person and/or reporting abuse
Well, here we go for some JS oneliner:
It works like this :
0|ilength (it will floor the number)reducemethod to loop through the built array. Use theaparameter, which is the response array (initialized as[]and updated at each iteration), and thelparameter which is the current index.aarray an item which is described as follow : Build al+1-long array, fill it withl+1(hence, if we are atl=1, the built item will be equal to[2, 2]). Then, use thejoinmethod to convert it to a string ('22'in this case)joinmethod one last time to add line breaks between linesPython
Rust :)
Playground link
JavaScript
Haskell
Output:
I think there is no new-line at the end.
Here is C++ solution:
Python one liner :
C#
Dart, didn't bother to deal with the float and use
dynamicPython ... slightly more verbose :)
My Swift solution :
swift
Here is my solution with Elixir
here is the output:
Shortest snippet among all! That's why I ❤️ Ruby.
Haskell
You could use
unlinesinstead ofintercalate "\n"to join the lines. Also, it looks like you have to support decimals.Python one-line solution