Created
May 28, 2020 23:52
-
-
Save Spuffynism/17f2317398b54b2df9213e7a30f4842d to your computer and use it in GitHub Desktop.
Print a nice graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bars = [1, 2, 4, 1, 4, 7, 2, 12, 12, 5]; | |
const heightOfGraph = Math.max(...bars); | |
let graph = ''; | |
for (let i = heightOfGraph; i > 0; i--) { | |
graph += bars.reduce((row, bar) => row + (i - bar > 0 ? ' ' : '+'), '') + '\n'; | |
} | |
console.log(graph); | |
/* | |
++ | |
++ | |
++ | |
++ | |
++ | |
+ ++ | |
+ ++ | |
+ +++ | |
+ ++ +++ | |
+ ++ +++ | |
++ ++++++ | |
++++++++++ | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment