From 27a88d8476f2a0853146c13ccfc98a35b908fcd1 Mon Sep 17 00:00:00 2001 From: David Ko Date: Wed, 14 Nov 2018 22:32:27 -0800 Subject: [PATCH 1/4] Create box_it_script_stretch project --- box_it_script_stretch.js | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 box_it_script_stretch.js diff --git a/box_it_script_stretch.js b/box_it_script_stretch.js new file mode 100755 index 0000000..d0a1733 --- /dev/null +++ b/box_it_script_stretch.js @@ -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)) \ No newline at end of file From d45672540dc0e672b3b2d689f12408727d4343b3 Mon Sep 17 00:00:00 2001 From: David Ko Date: Mon, 19 Nov 2018 21:26:09 -0800 Subject: [PATCH 2/4] Created and commited first version of turtle.js --- turtle.js | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 turtle.js diff --git a/turtle.js b/turtle.js new file mode 100644 index 0000000..e2a1f92 --- /dev/null +++ b/turtle.js @@ -0,0 +1,106 @@ +// worked on it on Monday Nov 19, 2018 at 930pm +class Turtle { + + constructor (x, y){ + this.x = x; + this.y = y; + this.face = 'east'; + this.coordinates = []; + this.coordinates.push([this.x, this.y]) + + } + + allPoints(){ + + return this.coordinates + + } + + forward(steps) { + + if (this.face === 'east'){ + for (let i = 0; i < steps; i++) { + this.x += 1; + this.coordinates.push([this.x, this.y]) + } + } else if (this.face === 'south') { + for (let i = 0; i < steps; i++) { + this.y += 1; + this.coordinates.push([this.x, this.y]) + } + } else if (this.face === 'west') { + for (let i = 0; i < steps; i++) { + this.x += -1; + this.coordinates.push([this.x, this.y]) + } + } else if (this.face === 'north') { + for (let i = 0; i < steps; i++) { + this.y += -1 + this.coordinates.push([this.x, this.y]) + } + } + } + right(){ + if (this.face === 'east') { + this.face = 'south' + } else if (this.face === 'south') { + this.face = 'west' + } else if (this.face === 'west') { + this.face = 'north' + } else if (this.face === 'north') { + this.face = 'east' + } + } + + left(){ + if (this.face === 'east') { + this.face = 'north' + } else if (this.face === 'north') { + this.face = 'west' + } else if (this.face === 'west') { + this.face = 'south' + } else if (this.face === 'south') { + this.face = 'east' + } + } + + myPrint(){ + let allCoordinates = this.coordinates; + let finalArray = []; + function toSortArray (x){ + let biggestX = 0 + let biggestY = 0 + for (let i = 0; i < x.length; i++){ + if(x[i][0] > biggestX){ + biggestX = x[i][0] + } + } + + for (let j = 0; j < x.length; j++){ + if(x[j][1] > biggestY){ + biggestY = x[j][1] + } + } + + finalArray.push([biggestX, biggestY]) + + } + toSortArray(allCoordinates) + return(finalArray) + } + +} + +let Sonic = new Turtle (0,0) +Sonic +Sonic.forward(5) +Sonic.right() +Sonic.forward(5) +Sonic.right() +Sonic.forward(5) +Sonic.right() +Sonic.forward(5) +Sonic.myPrint() + + + \ No newline at end of file From 7333aa6d44b68e6a07633cb5823b392a399b50d5 Mon Sep 17 00:00:00 2001 From: David Ko Date: Thu, 22 Nov 2018 21:20:45 -0800 Subject: [PATCH 3/4] Added print() method to complete my code --- turtle.js | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/turtle.js b/turtle.js index e2a1f92..bbc3c45 100644 --- a/turtle.js +++ b/turtle.js @@ -64,10 +64,13 @@ class Turtle { } } - myPrint(){ + print(){ let allCoordinates = this.coordinates; - let finalArray = []; - function toSortArray (x){ + let maxCoordinates = []; + let board = []; + let boardString = ''; + + function findMax (x){ let biggestX = 0 let biggestY = 0 for (let i = 0; i < x.length; i++){ @@ -75,19 +78,48 @@ class Turtle { biggestX = x[i][0] } } - for (let j = 0; j < x.length; j++){ if(x[j][1] > biggestY){ biggestY = x[j][1] } } - finalArray.push([biggestX, biggestY]) + maxCoordinates.push([biggestX, biggestY]) } - toSortArray(allCoordinates) - return(finalArray) - } + findMax(allCoordinates) + // return maxCoordinates + + + function makeBoard(width, height){ + for (let i = 0; i<=height; i++){ + for (let j = 0; j<=width; j++){ + board.push([j, i]) + } + } + } + makeBoard(maxCoordinates[0][0], maxCoordinates[0][1]) + // return board + function printBoard(board, width){ + // console.log(board.length) + for(let boardPoint = 0; boardPoint < board.length; boardPoint++ ){ + let currentPoint = board[boardPoint]; + let isTurtleStep = allCoordinates.find((step) => { + // console.log(step[0], 'step') + // console.log(currentPoint[0], 'currentPoint') + return (step[0] === currentPoint[0]) && (step[1] === currentPoint[1]) + }) + if (currentPoint[0] === width){ // width - 1? + boardString += isTurtleStep ? '* \n' : '0 \n'; + } else { + boardString += isTurtleStep ? '*' : '0'; + } + } + // console.log(boardString) + } + printBoard(board, maxCoordinates[0][0]) + console.log(boardString) + } } From c589dd1c036999884316a76acc5537d4f4aa1990 Mon Sep 17 00:00:00 2001 From: David-Ko <43652043+David-Ko@users.noreply.github.com> Date: Thu, 22 Nov 2018 21:37:08 -0800 Subject: [PATCH 4/4] pushed updated code for turtle.js to wrong branch pushed updated code for turtle.js to wrong branch --- turtle.js | 138 ------------------------------------------------------ 1 file changed, 138 deletions(-) delete mode 100644 turtle.js diff --git a/turtle.js b/turtle.js deleted file mode 100644 index bbc3c45..0000000 --- a/turtle.js +++ /dev/null @@ -1,138 +0,0 @@ -// worked on it on Monday Nov 19, 2018 at 930pm -class Turtle { - - constructor (x, y){ - this.x = x; - this.y = y; - this.face = 'east'; - this.coordinates = []; - this.coordinates.push([this.x, this.y]) - - } - - allPoints(){ - - return this.coordinates - - } - - forward(steps) { - - if (this.face === 'east'){ - for (let i = 0; i < steps; i++) { - this.x += 1; - this.coordinates.push([this.x, this.y]) - } - } else if (this.face === 'south') { - for (let i = 0; i < steps; i++) { - this.y += 1; - this.coordinates.push([this.x, this.y]) - } - } else if (this.face === 'west') { - for (let i = 0; i < steps; i++) { - this.x += -1; - this.coordinates.push([this.x, this.y]) - } - } else if (this.face === 'north') { - for (let i = 0; i < steps; i++) { - this.y += -1 - this.coordinates.push([this.x, this.y]) - } - } - } - right(){ - if (this.face === 'east') { - this.face = 'south' - } else if (this.face === 'south') { - this.face = 'west' - } else if (this.face === 'west') { - this.face = 'north' - } else if (this.face === 'north') { - this.face = 'east' - } - } - - left(){ - if (this.face === 'east') { - this.face = 'north' - } else if (this.face === 'north') { - this.face = 'west' - } else if (this.face === 'west') { - this.face = 'south' - } else if (this.face === 'south') { - this.face = 'east' - } - } - - print(){ - let allCoordinates = this.coordinates; - let maxCoordinates = []; - let board = []; - let boardString = ''; - - function findMax (x){ - let biggestX = 0 - let biggestY = 0 - for (let i = 0; i < x.length; i++){ - if(x[i][0] > biggestX){ - biggestX = x[i][0] - } - } - for (let j = 0; j < x.length; j++){ - if(x[j][1] > biggestY){ - biggestY = x[j][1] - } - } - - maxCoordinates.push([biggestX, biggestY]) - - } - findMax(allCoordinates) - // return maxCoordinates - - - function makeBoard(width, height){ - for (let i = 0; i<=height; i++){ - for (let j = 0; j<=width; j++){ - board.push([j, i]) - } - } - } - makeBoard(maxCoordinates[0][0], maxCoordinates[0][1]) - // return board - function printBoard(board, width){ - // console.log(board.length) - for(let boardPoint = 0; boardPoint < board.length; boardPoint++ ){ - let currentPoint = board[boardPoint]; - let isTurtleStep = allCoordinates.find((step) => { - // console.log(step[0], 'step') - // console.log(currentPoint[0], 'currentPoint') - return (step[0] === currentPoint[0]) && (step[1] === currentPoint[1]) - }) - if (currentPoint[0] === width){ // width - 1? - boardString += isTurtleStep ? '* \n' : '0 \n'; - } else { - boardString += isTurtleStep ? '*' : '0'; - } - } - // console.log(boardString) - } - printBoard(board, maxCoordinates[0][0]) - console.log(boardString) - } - -} - -let Sonic = new Turtle (0,0) -Sonic -Sonic.forward(5) -Sonic.right() -Sonic.forward(5) -Sonic.right() -Sonic.forward(5) -Sonic.right() -Sonic.forward(5) -Sonic.myPrint() - - - \ No newline at end of file