Advertisement
Guest User

Untitled

a guest
May 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.88 KB | None | 0 0
  1. func demoSimplePrintTable() {
  2.     let rowLabels = [
  3.         "row 1",
  4.         "row 2",
  5.         "row 3 looooong"
  6.     ]
  7.     let columnLabels = [
  8.         "column 1 loooong",
  9.         "column 2",
  10.         "column 3"
  11.     ]
  12.     let data = [
  13.         [100, 20, 30],
  14.         [1, 5, 10],
  15.         [1000, 4, 200000000]
  16.     ]
  17.    
  18.     printTable(rl : rowLabels, cl : columnLabels, data : data)
  19. }
  20. func printTable(rl : [String], cl : [String], data : [[Int]]) {
  21.    
  22.     for (i, clabel) in cl.enumerated(){
  23.         if i < 1 {
  24.             print("rien | ", terminator:"")
  25.         }
  26.         print (clabel + " | ", terminator:"")
  27.     }
  28.    
  29.     print("")
  30.    
  31.     for (j,rlabel) in rl.enumerated() {
  32.         print(rlabel, terminator:" | ");
  33.             for x in data[j] {
  34.                 print(x, terminator:" | ")
  35.             }
  36.         print("")
  37.     }
  38. }
  39.  
  40. demoSimplePrintTable()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement