Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions box_it_script_stretch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/Users/davidko/.nvm/versions/node/v11.1.0/bin/node

/**S T R E T C H #1
* step 1: In command line, type 'which node' to find the path
* step 2: add the path with the syntax in line 1 of this file
* step 3: In command line, type chmod +x boxItScript_stretch.js
* step 4: In command line, run the file by typing ./boxIt_final_node_stretch.js
*/

let i = 2
let arr = []

while (typeof process.argv[i] !== 'undefined'){
let x = process.argv[i]
arr.push(x);
i++;
}

function boxIt (x) {
let length = 0;
for (let i = 0; i < x.length; i++){
if (x[i].length > length){
length = x[i].length
}
}
//top border
let top = function drawTopBorder(x){
if(x){
return '┏' + '-'.repeat(x) +'┓'+'\n'
} else if (x === 0) {
return '┏┓' + '\n'
}
}
//middle border
let middle = function drawMiddleBorder(x) {
if (x){
return '┣' + '-'.repeat(x) + '┫'+'\n'
} else if (x === 0) {
return '┣┫'
}
}
//bottom border
let bottom = function drawBottomBorder(x){
if (x){
return '┗' + '-'.repeat(x) + '┛'
} else if (x === 0) {
return '┗┛'
}
}
//around border
let around = function drawBarsAround(x){
let m = '';
let j = String.fromCharCode(160)
for (let i of x){
let k = length - i.length
if (x.indexOf(i) !== x.length-1){
m += `┃${i}${j.repeat(k)}┃`+'\n' + middle(length)
}else{
m += `┃${i}${j.repeat(k)}┃`+'\n'
}
}
return m
}

if (length === 0){
return top(length) + bottom(length)
} else {
return top(length) + around(x) + bottom(length)
}
}


console.log(boxIt(arr))