From ec727c66f0887303ad92520a8dbf894a023753b3 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Fri, 28 Jan 2022 15:09:20 -0800 Subject: [PATCH 1/4] test file --- box-it-script/test.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 box-it-script/test.js diff --git a/box-it-script/test.js b/box-it-script/test.js new file mode 100644 index 0000000..e69de29 From 7be62034b62ae24fc34e09cbf583726b26e0ab87 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Fri, 4 Feb 2022 23:10:35 -0800 Subject: [PATCH 2/4] Week 1 Assignment --- .gitignore | 344 ----------------------------------------- box-it-script/test.js | 0 box-it-script/week1.js | 74 +++++++++ 3 files changed, 74 insertions(+), 344 deletions(-) delete mode 100644 .gitignore delete mode 100644 box-it-script/test.js create mode 100644 box-it-script/week1.js diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 798afd0..0000000 --- a/.gitignore +++ /dev/null @@ -1,344 +0,0 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/react,ruby,java,linux,macos,node,rails -# Edit at https://www.toptal.com/developers/gitignore?templates=react,ruby,java,linux,macos,node,rails - -### Java ### -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -replay_pid* - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### macOS ### -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Node ### -# Logs -logs -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* -.pnpm-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# Snowpack dependency directory (https://snowpack.dev/) -web_modules/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variable files -.env -.env.development.local -.env.test.local -.env.production.local -.env.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next -out - -# Nuxt.js build / generate output -.nuxt -dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# vuepress v2.x temp and cache directory -.temp - -# Docusaurus cache and generated files -.docusaurus - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# yarn v2 -.yarn/cache -.yarn/unplugged -.yarn/build-state.yml -.yarn/install-state.gz -.pnp.* - -### Node Patch ### -# Serverless Webpack directories -.webpack/ - -# Optional stylelint cache - -# SvelteKit build / generate output -.svelte-kit - -### Rails ### -*.rbc -capybara-*.html -.rspec -/db/*.sqlite3 -/db/*.sqlite3-journal -/db/*.sqlite3-[0-9]* -/public/system -/coverage/ -/spec/tmp -*.orig -rerun.txt -pickle-email-*.html - -# Ignore all logfiles and tempfiles. -/log/* -/tmp/* -!/log/.keep -!/tmp/.keep - -# TODO Comment out this rule if you are OK with secrets being uploaded to the repo -config/initializers/secret_token.rb -config/master.key - -# Only include if you have production secrets in this file, which is no longer a Rails default -# config/secrets.yml - -# dotenv, dotenv-rails -# TODO Comment out these rules if environment variables can be committed -.env*.local - -## Environment normalization: -/.bundle -/vendor/bundle - -# these should all be checked in to normalize the environment: -# Gemfile.lock, .ruby-version, .ruby-gemset - -# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: -.rvmrc - -# if using bower-rails ignore default bower_components path bower.json files -/vendor/assets/bower_components -*.bowerrc -bower.json - -# Ignore pow environment settings -.powenv - -# Ignore Byebug command history file. -.byebug_history - -# Ignore node_modules - -# Ignore precompiled javascript packs -/public/packs -/public/packs-test -/public/assets - -# Ignore yarn files -/yarn-error.log - -# Ignore uploaded files in development -/storage/* -!/storage/.keep -/public/uploads - -### react ### -.DS_* -**/*.backup.* -**/*.back.* - -node_modules - -*.sublime* - -psd -thumb -sketch - -### Ruby ### -*.gem -/.config -/InstalledFiles -/pkg/ -/spec/reports/ -/spec/examples.txt -/test/tmp/ -/test/version_tmp/ -/tmp/ - -# Used by dotenv library to load environment variables. -# .env - -# Ignore Byebug command history file. - -## Specific to RubyMotion: -.dat* -.repl_history -build/ -*.bridgesupport -build-iPhoneOS/ -build-iPhoneSimulator/ - -## Specific to RubyMotion (use of CocoaPods): -# -# We recommend against adding the Pods directory to your .gitignore. However -# you should judge for yourself, the pros and cons are mentioned at: -# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control -# vendor/Pods/ - -## Documentation cache and generated files: -/.yardoc/ -/_yardoc/ -/doc/ -/rdoc/ - -/.bundle/ -/lib/bundler/man/ - -# for a library or gem, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# Gemfile.lock -# .ruby-version -# .ruby-gemset - -# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: - -# Used by RuboCop. Remote config files pulled in from inherit_from directive. -# .rubocop-https?--* - -# End of https://www.toptal.com/developers/gitignore/api/react,ruby,java,linux,macos,node,rails diff --git a/box-it-script/test.js b/box-it-script/test.js deleted file mode 100644 index e69de29..0000000 diff --git a/box-it-script/week1.js b/box-it-script/week1.js new file mode 100644 index 0000000..26bd0c9 --- /dev/null +++ b/box-it-script/week1.js @@ -0,0 +1,74 @@ +// This function takes a number as an argument and returns that number of horizontal bars as a string. +function drawLine(num){ + return '─'.repeat(num); +}; + + + +// This function takes a number as an argument and draw a top border. +function drawTopBorder(num){ + return '┌' + drawLine(num) + '┐'; +}; + + + +// This function takes a number as an argument and draw a middle border. +function drawMiddleBorder(num){ + return '├' + drawLine(num) + '┤'; +}; + + + +// This function takes a number as an argument and draw a bottom border. +function drawBottomBorder(num){ + return '└' + drawLine(num) + '┘'; +}; + + + +// This function takes a string as an arguments and surrounds it with vertical lines and returns it. +function drawBarsAround(str, num){ + return '│' + str + ' '.repeat(num - str.length) + '│'; +}; + + + +//This function that takes an array of strings and returns a string where each is in a single column table. +//To add "new lines" to a string, use the \n special character. In a string, \n characters will +//display as new lines when logged with console.log(...). + +function boxIt(arr){ + let longest = arr[0]; + let result = ''; + + for (let str of arr){ + if (str.length > longest.length){ + longest = str; + } + } + + const num = longest.length; + + for (let i = 0; i < arr.length; i++){ + if (arr.length === 1){ + result += `${drawTopBorder(num)}\n${drawBarsAround(arr[i], num)}\n${drawBottomBorder(num)}`; + } else if (i === 0){ + result += `${drawTopBorder(num)}\n${drawBarsAround(arr[i], num)}\n`; + } else if (i > 0 && i < arr.length - 1){ + result += `${drawMiddleBorder(num)}\n${drawBarsAround(arr[i], num)}\n${drawMiddleBorder(num)}\n`; + } else { + result += `${drawBarsAround(arr[i], num)}\n${drawBottomBorder(num)}`; + } + } + return result; +}; + + + +console.log(boxIt(['Coding'])); +console.log(boxIt(['JavaScript', 'Ruby', 'HTML&CSS'])); + + + + + From f2c78312bfb523acc517d6c34a658b624fcc423f Mon Sep 17 00:00:00 2001 From: Ibrahim <98372964+abe2dev@users.noreply.github.com> Date: Tue, 8 Feb 2022 23:01:59 -0800 Subject: [PATCH 3/4] My second homework --- turtle_graphics_2/turtle.js | 149 ++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 turtle_graphics_2/turtle.js diff --git a/turtle_graphics_2/turtle.js b/turtle_graphics_2/turtle.js new file mode 100644 index 0000000..97ece77 --- /dev/null +++ b/turtle_graphics_2/turtle.js @@ -0,0 +1,149 @@ +/* In this homework, you will create a simple drawing program inspired +by Turtle Graphics. It will be a much simpler implementation that will +only accept right angles (90 degrees). +*/ + +// Create the Turtle class with initial position +class Turtle { + constructor (x, y) { + this.x = x || 0; + this.y = y || 0; + this.direction = 'east'; + this.angle = 0; + this.steps = [ + [this.x, this.y] + ]; + }; + +/* Forward method that takes a number of steps then updates the Turtle +instance with its new position after moving that many steps. Keep track +of every movement the turtle makes including the first one. +*/ + +forward (step) { + for (let i = 0; i < step; i++) { + if (this.angle === 0) { + this.x++; + } else if (this.angle === 90) { + this.y--; + } else if (this.angle === 180) { + this.x--; + } else if (this.angle === 270) { + this.y++; + } else { + return this; + } + this.steps.push([this.x, this.y]); + } + return this; +} + +/* Create a right method that takes zero arguments. When right is called, +update the Turtle instance to rotate its facing to the right. A turtle +should begin facing east. +*/ + +right () { + this.angle += 90; + if (this.angle === 90) { + this.direction = 'south'; + } else if (this.angle === 180) { + this.direction = 'west'; + } else if (this.angle === 270) { + this.direction = 'north'; + } else { + this.direction = 'east'; + this.angle = 0; + } + return this; +}; + +// Create a left method like right but turns the turtle's facing to the left. + +left () { + this.angle -= 90; + if (this.angle === 90) { + this.direction = 'south'; + } else if (this.angle === 180) { + this.direction = 'west'; + } else if (this.angle === -90 || this.angle === 270) { + this.angle = 270; + this.direction = 'north'; + } else { + this.direction = 'east'; + this.angle = 0; + } + return this; +}; + +/* Create an allPoints method which returns an array containing all +coordinates the turtle has walked over. +*/ + +allPoints () { + return this.steps; +}; + +/*Create a print method that draws the path that the turtle walked over +as a string and logs it to the console. +*/ + +print () { + let maxX = -Infinity; + let maxY = -Infinity; + let minX = Infinity; + let minY = Infinity; + for (let step of this.steps) { + if (step[0] > maxX) { + maxX = step[0]; + } + if (step[1] > maxY) { + maxY = step[1]; + } + if (step[0] < minX) { + minX = step[0]; + } + if (step[1] < minY) { + minY = step[1]; + } + }; + +const turtleFootprint = (x, y) => { + for (let step of this.steps) { + if (step[0] === x && step[1] === y) + return true; + } + return false; +}; + +console.log('-- BEGIN LOG'); +for (let y = maxY + 1; y >= minY; y--) { + let row = ''; + for (let x = minX; x <= maxX + 1; x++ ) { + if (turtleFootprint (x, y)) { + row += ' ○ '; + } else { + row += ' - '; + } + } + console.log(row); +} +console.log('-- END LOG'); +}; +}; + +const ringo = new Turtle(); +ringo.forward(3) + .left() + .forward(3) + .right() + .forward(5) + .right() + .forward(8) + .right() + .forward(5) + .right() + .forward(3) + .left() + .forward(3) + .print(); From 4510b6626181fe22d1667d8ea5fe6d8ccc06094e Mon Sep 17 00:00:00 2001 From: Ibrahim <98372964+abe2dev@users.noreply.github.com> Date: Wed, 9 Feb 2022 21:42:11 -0800 Subject: [PATCH 4/4] Delete box-it-script directory --- box-it-script/week1.js | 74 ------------------------------------------ 1 file changed, 74 deletions(-) delete mode 100644 box-it-script/week1.js diff --git a/box-it-script/week1.js b/box-it-script/week1.js deleted file mode 100644 index 26bd0c9..0000000 --- a/box-it-script/week1.js +++ /dev/null @@ -1,74 +0,0 @@ -// This function takes a number as an argument and returns that number of horizontal bars as a string. -function drawLine(num){ - return '─'.repeat(num); -}; - - - -// This function takes a number as an argument and draw a top border. -function drawTopBorder(num){ - return '┌' + drawLine(num) + '┐'; -}; - - - -// This function takes a number as an argument and draw a middle border. -function drawMiddleBorder(num){ - return '├' + drawLine(num) + '┤'; -}; - - - -// This function takes a number as an argument and draw a bottom border. -function drawBottomBorder(num){ - return '└' + drawLine(num) + '┘'; -}; - - - -// This function takes a string as an arguments and surrounds it with vertical lines and returns it. -function drawBarsAround(str, num){ - return '│' + str + ' '.repeat(num - str.length) + '│'; -}; - - - -//This function that takes an array of strings and returns a string where each is in a single column table. -//To add "new lines" to a string, use the \n special character. In a string, \n characters will -//display as new lines when logged with console.log(...). - -function boxIt(arr){ - let longest = arr[0]; - let result = ''; - - for (let str of arr){ - if (str.length > longest.length){ - longest = str; - } - } - - const num = longest.length; - - for (let i = 0; i < arr.length; i++){ - if (arr.length === 1){ - result += `${drawTopBorder(num)}\n${drawBarsAround(arr[i], num)}\n${drawBottomBorder(num)}`; - } else if (i === 0){ - result += `${drawTopBorder(num)}\n${drawBarsAround(arr[i], num)}\n`; - } else if (i > 0 && i < arr.length - 1){ - result += `${drawMiddleBorder(num)}\n${drawBarsAround(arr[i], num)}\n${drawMiddleBorder(num)}\n`; - } else { - result += `${drawBarsAround(arr[i], num)}\n${drawBottomBorder(num)}`; - } - } - return result; -}; - - - -console.log(boxIt(['Coding'])); -console.log(boxIt(['JavaScript', 'Ruby', 'HTML&CSS'])); - - - - -