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|i
length (it will floor the number)reduce
method to loop through the built array. Use thea
parameter, which is the response array (initialized as[]
and updated at each iteration), and thel
parameter which is the current index.a
array 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 thejoin
method to convert it to a string ('22'
in this case)join
method one last time to add line breaks between linesHaskell
Output:
Dart, didn't bother to deal with the float and use
dynamic
JavaScript
C#
I think there is no new-line at the end.
Here is C++ solution:
Python one liner :
Python ... slightly more verbose :)
Rust :)
Playground link
Python
My Swift solution :
swift
Here is my solution with Elixir
here is the output:
Haskell
You could use
unlines
instead ofintercalate "\n"
to join the lines. Also, it looks like you have to support decimals.Shortest snippet among all! That's why I ❤️ Ruby.
Python one-line solution