├── .gitignore ├── .markdownlint.json ├── .prettierignore ├── README.md ├── additional_resources ├── aa_holidays.png ├── advice_from_TAs.md ├── advice_from_students.md ├── archive │ ├── course_syllabus.png │ ├── dont-panic │ │ ├── README.md │ │ ├── bookmarks.png │ │ └── tree.png │ ├── setup_seminar.md │ └── syllabus.md ├── terminal_command_cheatsheet.md ├── week1 │ ├── setup_image_on_PT.md │ └── wslWorkflow.md └── week2 │ ├── gitflow │ ├── README.md │ ├── create-repo.png │ ├── gitignore-1.png │ ├── gitignore-2.png │ ├── gitignore-3.png │ ├── gitignore-4.png │ ├── gitignore-5.png │ ├── init-repo.png │ ├── lectures_1.png │ ├── lectures_2.png │ ├── lectures_3.png │ ├── look-like-repo.png │ └── push-repo.png │ └── terminal-commands.md ├── w1 ├── README.md ├── d2 │ ├── README.md │ ├── booleans.js │ ├── conditionals.js │ ├── functions.js │ ├── lecture.js │ ├── loop.js │ ├── numbers.js │ ├── scratch.js │ ├── strings.js │ └── variables.js ├── d3 │ ├── README.md │ ├── array-method.js │ ├── arrays.js │ ├── eod.js │ ├── function-expressions.js │ ├── hw-review.js │ ├── lecture.js │ ├── mutability.js │ ├── rotate.js │ └── unix.js ├── d4 │ ├── README.md │ ├── eod.js │ ├── helper_functions.js │ ├── images │ │ ├── pairs_in_arrays.png │ │ └── unique_pairs_in_arrays.png │ ├── lecture.js │ ├── mostVowels.js │ ├── nested-loop.js │ └── snakeToCamel.js └── d5 │ ├── lecture.js │ ├── maica-santos-aa01-assessment-practice-coding-problems-temp │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── problems │ │ ├── 01-string-changer.js │ │ ├── 02-debugging-is-sorted.js │ │ └── 03-most-expensive-groceries.js │ └── test │ │ ├── 01-string-changer-spec.js │ │ ├── 02-debugging-is-sorted-spec.js │ │ ├── 03-most-expensive-groceries-spec.js │ │ └── utils │ │ └── 02-debugging-is-sorted-original.js │ └── test.js ├── w2 ├── README.md ├── d1 │ ├── arrow_functions.js │ ├── lecture.js │ ├── pojo_demos │ │ ├── pojo_basics │ │ │ ├── 01-declare_key_values.js │ │ │ ├── 02-delete_keys_values.js │ │ │ ├── 03-using_variables_as_keys.js │ │ │ ├── 04-dot_vs_bracket_notation.js │ │ │ ├── 05-cat_builder.js │ │ │ ├── 06-check_if_key_is_in_object.js │ │ │ └── 07-nested_array_of_objects.js │ │ └── pojo_iteration │ │ │ ├── 01-iterate_through_obj.js │ │ │ ├── 02-using_Object.keys_I.js │ │ │ ├── 03-using_Object.keys_II.js │ │ │ ├── 04-using_Object.values.js │ │ │ ├── 05-check_if_value_is_in_obj.js │ │ │ ├── 06-using_Object.entries.js │ │ │ └── 07-refactoring_iteration.js │ ├── pojo_iteration.js │ └── pojo_lecutre.js ├── d2 │ ├── README.md │ ├── destructuring.js │ ├── lecture.js │ ├── rest-spread-repl.js │ └── rest_and_spread.js ├── d3 │ ├── README.md │ ├── callbacks.js │ ├── forOf-vs-forIn.js │ ├── lecture.js │ ├── nestedArr-repl.js │ ├── repl.js │ └── rest-spread.js ├── d4 │ ├── README.md │ ├── closure-repl.js │ ├── closure.js │ ├── lecture.js │ ├── scope.js │ └── scratch.js └── solutions │ ├── advanced-array-methods │ └── advanced-array │ │ ├── README.md │ │ ├── build_trigger.md │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── problems │ │ ├── 00-sum-forEach.js │ │ ├── 01-avg-val-forEach.js │ │ ├── 02-tripler-map.js │ │ ├── 03-long-words-filter.js │ │ ├── 04-remove-e-words-filter.js │ │ ├── 05-choosey-endings-filter.js │ │ ├── 06-sum-reduce.js │ │ ├── 07-max-reduce.js │ │ ├── 08-product-reduce.js │ │ ├── 09-snake-to-camel-map.js │ │ ├── 10-yeller-map.js │ │ ├── 11-has-three-vowels.js │ │ ├── 12-longest-word.js │ │ ├── 13-unique.js │ │ ├── 14-shortest-word.js │ │ ├── 15-choose-primes.js │ │ ├── 16-hipsterfy.js │ │ ├── 17-repeating-translate.js │ │ └── 18-two-d-product.js │ │ └── test │ │ ├── 00-sum-forEach-spec.js │ │ ├── 01-avg-val-forEach-spec.js │ │ ├── 02-tripler-map-spec.js │ │ ├── 03-long-words-filter-spec.js │ │ ├── 04-remove-e-words-filter-spec.js │ │ ├── 05-choosey-endings-spec.js │ │ ├── 06-sum-reduce-spec.js │ │ ├── 07-max-reduce-spec.js │ │ ├── 08-product-reduce-spec.js │ │ ├── 09-snake-to-camel-spec.js │ │ ├── 10-yeller-map-spec.js │ │ ├── 11-has-three-vowels-spec.js │ │ ├── 12-longest-word-spec.js │ │ ├── 13-unique-spec.js │ │ ├── 14-shortest-word-spec.js │ │ ├── 15-choose-primes-spec.js │ │ ├── 16-hipsterfy-spec.js │ │ ├── 17-repeating-translate-spec.js │ │ └── 18-two-d-product-spec.js │ ├── callbacks │ └── try-out-callbacks │ │ ├── README.md │ │ ├── build_trigger.md │ │ ├── naughty_list.md │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── problems │ │ ├── 01-my-for-each.js │ │ ├── 02-my-map.js │ │ ├── 03-multi-map.js │ │ ├── 04-my-filter.js │ │ ├── 05-selective-map.js │ │ ├── 06-reject.js │ │ ├── 07-my-some.js │ │ ├── 08-count.js │ │ ├── 09-chain-map.js │ │ ├── 10-my-every.js │ │ ├── 11-and-select.js │ │ ├── 12-exactly.js │ │ ├── 13-min-value-callback.js │ │ ├── 14-map-mutator.js │ │ ├── 15-sentence-mapper.js │ │ ├── 16-suffix-cipher.js │ │ ├── 17-xor-select.js │ │ ├── 18-one.js │ │ ├── 19-greater-callback-value.js │ │ ├── 20-none.js │ │ ├── 21-at-most.js │ │ ├── 22-first-index.js │ │ ├── 23-alternating-map.js │ │ └── 24-my-simple-reduce.js │ │ ├── pt-split │ │ ├── part-1.md │ │ ├── part-2.md │ │ ├── part-3.md │ │ └── part-4.md │ │ └── test │ │ ├── 01-my-for-each-test.js │ │ ├── 02-my-map-test.js │ │ ├── 03-multi-map-test.js │ │ ├── 04-my-filter-test.js │ │ ├── 05-selective-map-test.js │ │ ├── 06-reject-test.js │ │ ├── 07-my-some-test.js │ │ ├── 08-count-test.js │ │ ├── 09-chain-map-test.js │ │ ├── 10-my-every-test.js │ │ ├── 11-and-select-test.js │ │ ├── 12-exactly-test.js │ │ ├── 13-min-value-callback-test.js │ │ ├── 14-map-mutator-test.js │ │ ├── 15-sentence-mapper-test.js │ │ ├── 16-suffix-cipher-test.js │ │ ├── 17-xor-select-test.js │ │ ├── 18-one-test.js │ │ ├── 19-greater-callback-value-test.js │ │ ├── 20-none-test.js │ │ ├── 21-at-most-test.js │ │ ├── 22-first-index-test.js │ │ ├── 23-alternating-map-test.js │ │ └── 24-my-simple-reduce-test.js │ ├── pojo-fruits │ ├── README.md │ ├── build_trigger.md │ ├── fruit-data.js │ ├── ghapp.config.json │ ├── package-lock.json │ ├── package.json │ ├── problems │ │ ├── 01-fruit-data-structure.js │ │ └── 02-manipulate-fruit-objects.js │ └── test │ │ ├── 01-fruit-data-structure-spec.js │ │ └── 02-manipulate-fruit-objects-spec.js │ ├── pojo-practice │ └── pojo-basics │ │ ├── README.md │ │ ├── build_trigger.md │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── problems │ │ ├── 01-keys-in-object.js │ │ ├── 02-values-in-object.js │ │ ├── 03-set-key-in-object.js │ │ ├── 04-get-full-name.js │ │ ├── 05-does-key-exist.js │ │ ├── 06-key-in-object-array.js │ │ ├── 07-value-pair.js │ │ ├── 08-apple-counter.js │ │ ├── 09-array-converter.js │ │ ├── 10-string-converter.js │ │ └── 11-count-scores.js │ │ └── test │ │ ├── 01-keys-in-object.js │ │ ├── 02-values-in-object.js │ │ ├── 03-set-key-in-object.js │ │ ├── 04-get-full-name.js │ │ ├── 05-does-key-exist.js │ │ ├── 06-key-in-object-array.js │ │ ├── 07-value-pair.js │ │ ├── 08-apple-counter.js │ │ ├── 09-array-converter.js │ │ ├── 10-string-converter.js │ │ └── 11-count-scores.js │ └── scope-problems-without-context │ ├── README.md │ ├── build_trigger.md │ ├── naughty_list.md │ ├── package-lock.json │ ├── package.json │ ├── problems │ ├── 00-arrow-addfive.js │ ├── 01-arrow-full-name.js │ ├── 02-arrow-my-map.js │ ├── 03-arrow-rest-sum.js │ ├── 04-arrow-average-value.js │ ├── 05-arrow-mirror-array.js │ ├── 06-closure-sandwiches.js │ ├── 07-set-time-out.js │ ├── 08-hidden-counter.js │ ├── 09-interrupter.js │ ├── 10-count-down.js │ ├── 11-lazy-adder.js │ ├── 12-volume.js │ ├── 13-dynamic-divide.js │ ├── 14-smoothie-machine.js │ ├── 15-closure-dynamic-multi.js │ ├── 16-coupon.js │ ├── 17-arrow-reverse.js │ ├── 18-planned-intersection.js │ ├── 19-coin-collector.js │ └── 20-curried-sum.js │ ├── pt-split │ ├── part-1.md │ ├── part-2.md │ ├── part-3.md │ └── part-4.md │ └── test │ ├── 00-arrow-addfive-spec.js │ ├── 01-arrow-full-name-spec.js │ ├── 02-arrow-my-map-spec.js │ ├── 03-arrow-rest-sum-spec.js │ ├── 04-arrow-average-value-spec.js │ ├── 05-arrow-mirror-array-spec.js │ ├── 06-closure-sandwiches-spec.js │ ├── 07-set-time-out-spec.js │ ├── 08-hidden-counter-spec.js │ ├── 09-interrupter-spec.js │ ├── 10-count-down-spec.js │ ├── 11-lazy-adder-spec.js │ ├── 12-volume-spec.js │ ├── 13-dynamic-divide-spec.js │ ├── 14-smoothie-machine-spec.js │ ├── 15-closure-dynamic-multi-spec.js │ ├── 16-coupon-spec.js │ ├── 17-arrow-reverse-spec.js │ ├── 18-planned-intersection-spec.js │ ├── 19-coin-collector-spec.js │ └── 20-curried-sum-spec.js └── w3 ├── README.md ├── d1 ├── README.md ├── debugger.js ├── lecture.js └── string-interpolation.js ├── d2 ├── README.md ├── eod.js ├── fib_with_chris_and_kirubel.js ├── lecture.js ├── recursion.js ├── sort.js ├── sum-array.js ├── sum-to-n.js └── tree_recursion.png ├── d3 ├── README.md ├── deepDup.js ├── first_class_obj.js ├── flasey_values.js ├── hoisting.js ├── iife.js ├── lecture.js ├── prim_vs_reference.js ├── shallow-vs-deep.js └── solutions │ ├── recursion-pt1 │ ├── README.md │ ├── build_trigger.md │ ├── ghapp.config.json │ ├── package-lock.json │ ├── package.json │ ├── problems │ │ ├── 01-sum-to-n.js │ │ ├── 02-sum-array.js │ │ ├── 03-ice-cream-shop.js │ │ └── 04-range.js │ └── test │ │ ├── 01-sum-to-n-spec.js │ │ ├── 02-sum-array-spec.js │ │ ├── 03-ice-cream-shop-spec.js │ │ ├── 04-range-spec.js │ │ └── util │ │ ├── deep-includes-order-matters.js │ │ └── deep-includes.js │ ├── recursion-pt2 │ ├── README.md │ ├── build_trigger.md │ ├── ghapp.config.json │ ├── package-lock.json │ ├── package.json │ ├── problems │ │ ├── 05-reverse.js │ │ ├── 06-add-to-twelve.js │ │ ├── 07-exponent.js │ │ └── 08-advanced-exponent.js │ └── test │ │ ├── 05-reverse-spec.js │ │ ├── 06-add-to-twelve-spec.js │ │ ├── 07-exponent-spec.js │ │ ├── 08-advanced-exponent-spec.js │ │ └── util │ │ ├── deep-includes-order-matters.js │ │ └── deep-includes.js │ ├── recursion-pt3 │ ├── README.md │ ├── build_trigger.md │ ├── ghapp.config.json │ ├── package-lock.json │ ├── package.json │ ├── problems │ │ ├── 09-fibonacci.js │ │ ├── 10-factorial.js │ │ ├── 11-flatten.js │ │ └── 12-is-sorted.js │ └── test │ │ ├── 09-fibonacci-spec.js │ │ ├── 10-factorial-spec.js │ │ ├── 11-flatten-spec.js │ │ ├── 12-is-sorted-spec.js │ │ └── util │ │ ├── deep-includes-order-matters.js │ │ └── deep-includes.js │ └── recursion-pt4 │ ├── README.md │ ├── build_trigger.md │ ├── ghapp.config.json │ ├── package-lock.json │ ├── package.json │ ├── problems │ ├── 13-sort.js │ ├── 14-deep-dup.js │ ├── 15-bonus-subsets.js │ ├── 16-bonus-make-tree.js │ ├── 17-bonus-permutations.js │ └── 18-bonus-make-change.js │ └── test │ ├── 13-sort-spec.js │ ├── 14-deep-dup-spec.js │ ├── 15-subsets-spec.js │ ├── 16-make-tree-spec.js │ ├── 17-permutations-spec.js │ ├── 18-make-change-spec.js │ └── util │ ├── deep-includes-order-matters.js │ └── deep-includes.js ├── d4 ├── README.md ├── eod.js ├── images │ └── threading.png ├── lecture.js ├── setInterval.js ├── solutions │ ├── timeout-pt1 │ │ ├── README.md │ │ ├── build_trigger.md │ │ ├── ghapp.config.json │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── problems │ │ │ ├── 01-set-seconds-timeout.js │ │ │ ├── 02-set-seconds-timeout-args.js │ │ │ ├── 03-batch-timeouts.js │ │ │ └── 04-interval-count.js │ │ └── test │ │ │ ├── 01-set-seconds-timeout-spec.js │ │ │ ├── 02-set-seconds-timeout-args-spec.js │ │ │ ├── 03-batch-timeouts-spec.js │ │ │ └── 04-interval-count-spec.js │ └── timeout-pt2 │ │ ├── README.md │ │ ├── build_trigger.md │ │ ├── ghapp.config.json │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── problems │ │ ├── 05-postpone.js │ │ ├── 06-dynamic-interval-count.js │ │ └── 07-postpone-with-args.js │ │ └── test │ │ ├── 05-postpone-spec.js │ │ ├── 06-dynamic-interval-count-spec.js │ │ └── 07-postpone-with-args-spec.js └── whiteboarding.md └── d5 ├── aa03-assessment-practice-01-most-frequent-vowel ├── README.md ├── package-lock.json ├── package.json ├── problems │ └── 01-most-frequent-vowel.js └── test │ └── 01-most-frequent-vowel-spec.js ├── aa03-assessment-practice-02-print-outer-nums-first ├── README.md ├── package-lock.json ├── package.json ├── problems │ └── 02-print-outer-nums-first.js └── test │ └── 02-print-outer-nums-first-spec.js ├── aa03-assessment-practice-03-eliminate-type ├── README.md ├── package-lock.json ├── package.json ├── problems │ └── 03-eliminate-type.js └── test │ └── 03-eliminate-type-spec.js ├── aa03-assessment-practice-04-print-and-pause ├── README.md ├── package-lock.json ├── package.json ├── problems │ └── 04-print-and-pause.js └── test │ └── 04-print-and-pause-spec.js ├── free_response.js ├── scratch.js └── solutions └── bonus-practices └── additional-practice ├── README.md ├── build_trigger.md ├── package-lock.json ├── package.json ├── problems ├── 01-r2d2-speaks.js ├── 02-recursive-sort.js ├── 03-even-number-range.js ├── 04-dynamic-slice.js ├── 05-preserve-types.js └── 06-recursive-preserve-type.js └── test ├── 01-r2d2-speaks-spec.js ├── 02-recursive-sort-spec.js ├── 03-even-number-range-spec.js ├── 04-dynamic-slice-spec.js ├── 05-preserve-types-spec.js └── 06-recursive-preserve-type-spec.js /.gitignore: -------------------------------------------------------------------------------- 1 | */.DS_Store/* 2 | .DS_Store 3 | .vscode 4 | notes.js 5 | node_modules/ 6 | 7 | -------------------------------------------------------------------------------- /.markdownlint.json: -------------------------------------------------------------------------------- 1 | { 2 | "MD033": false 3 | } 4 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | *.md -------------------------------------------------------------------------------- /additional_resources/aa_holidays.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/aa_holidays.png -------------------------------------------------------------------------------- /additional_resources/archive/course_syllabus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/archive/course_syllabus.png -------------------------------------------------------------------------------- /additional_resources/archive/dont-panic/bookmarks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/archive/dont-panic/bookmarks.png -------------------------------------------------------------------------------- /additional_resources/archive/dont-panic/tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/archive/dont-panic/tree.png -------------------------------------------------------------------------------- /additional_resources/archive/syllabus.md: -------------------------------------------------------------------------------- 1 | # Course Syllabus and Holidays 2 | ![Course Syllabus](./course_syllabus.png "Course Syllabus") 3 | ![aA Holidays](./aa_holidays.png "aA Holidays") -------------------------------------------------------------------------------- /additional_resources/week1/setup_image_on_PT.md: -------------------------------------------------------------------------------- 1 | # Progress Tracker Image Setup 2 | 3 | ## Let's setup your profile image on Progress Tracker 4 | 5 | --- 6 | 7 | ### Step 1 8 | 9 | - With the email linked to Progress Tracker, create a new [Wordpress Account](https://wordpress.com/start/user) 10 | 11 | ### Step 2 12 | 13 | - Login with your new Wordpress Account at [Gravatar](https://en.gravatar.com/) 14 | 15 | ### Step 3 16 | 17 | - Upon login, click the **Add a new image** button 18 | - Click **Upload new** 19 | - Choose your image to upload 20 | - Click **Next** 21 | - Crop your image to your liking 22 | - set rating to G 23 | 24 | ### Step 4 25 | 26 | - DONE! 27 | - It may take a few minutes to reflect on your Progress Tracker profile 28 | 29 | ### NOTE 30 | 31 | - If something is confusing or isn't working, reach out to an instructor for help! 32 | -------------------------------------------------------------------------------- /additional_resources/week2/gitflow/create-repo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/week2/gitflow/create-repo.png -------------------------------------------------------------------------------- /additional_resources/week2/gitflow/gitignore-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/week2/gitflow/gitignore-1.png -------------------------------------------------------------------------------- /additional_resources/week2/gitflow/gitignore-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/week2/gitflow/gitignore-2.png -------------------------------------------------------------------------------- /additional_resources/week2/gitflow/gitignore-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/week2/gitflow/gitignore-3.png -------------------------------------------------------------------------------- /additional_resources/week2/gitflow/gitignore-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/week2/gitflow/gitignore-4.png -------------------------------------------------------------------------------- /additional_resources/week2/gitflow/gitignore-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/week2/gitflow/gitignore-5.png -------------------------------------------------------------------------------- /additional_resources/week2/gitflow/init-repo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/week2/gitflow/init-repo.png -------------------------------------------------------------------------------- /additional_resources/week2/gitflow/lectures_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/week2/gitflow/lectures_1.png -------------------------------------------------------------------------------- /additional_resources/week2/gitflow/lectures_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/week2/gitflow/lectures_2.png -------------------------------------------------------------------------------- /additional_resources/week2/gitflow/lectures_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/week2/gitflow/lectures_3.png -------------------------------------------------------------------------------- /additional_resources/week2/gitflow/look-like-repo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/week2/gitflow/look-like-repo.png -------------------------------------------------------------------------------- /additional_resources/week2/gitflow/push-repo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/additional_resources/week2/gitflow/push-repo.png -------------------------------------------------------------------------------- /additional_resources/week2/terminal-commands.md: -------------------------------------------------------------------------------- 1 | # Command Line Cheat Sheet 2 | 3 | | Command | Description | 4 | | ----------- | ----------- | 5 | | mkdir \ | Create a new folder with the given name | 6 | | cd \ | Change into directory with the given name/path | 7 | | cd .. | Move back one directory | 8 | | ls | Look at the items in the current directory | 9 | | touch \ | Make a new file in current directory | 10 | | rm \ | Delete folder with given name/path | 11 | | rm -rf \ | Delete folder with the given name/path | 12 | | pwd | Print working directory | -------------------------------------------------------------------------------- /w1/d2/scratch.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | // console.log('hello ' + 'maica'); 5 | // console.log('hello ' + 'brandon'); 6 | // console.log('hello ' + 'johnny'); 7 | 8 | function myFunc(name){ 9 | // console.log(`hello ${name}`); 10 | name = name.toUpperCase(); 11 | // return `hello ${name}` 12 | // console.log('do we reach this console.log?'); 13 | for(let i = 0; i < 4; i++){ 14 | console.log(i); 15 | return 'done' 16 | } 17 | }; 18 | 19 | // want to see output 20 | // wrap the function call in a console.log 21 | // this is the function call! 22 | // console.log('the return value of myfunc =>',myFunc('maica')); 23 | 24 | 25 | //input - maica 26 | //output - the return value of the function 27 | 28 | // myFunc('brandon'); 29 | // myFunc('johnny'); 30 | 31 | 32 | 33 | 34 | // declare function 35 | // param1 = 25 36 | // param2 = 17 37 | function math(num1, num2){ 38 | // console.log('num1', num1, 'num2', num2); 39 | 40 | return num1 + num2; 41 | }; 42 | 43 | 44 | // call/invoke that function 45 | let num = 10 46 | // console.log('return value of math 1',math(30, num)); 47 | 48 | // console.log('return value of math 2',math(25, 17)); 49 | // arguments 10 and num 50 | -------------------------------------------------------------------------------- /w1/d3/lecture.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/w1/d3/lecture.js -------------------------------------------------------------------------------- /w1/d3/mutability.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Mutability 4 | * Mutability is the concept of certain pieces of data being able to changed or mutated.Of the datatypes that we've seen so far, only arrays are mutable. 5 | 6 | Mutable - can be changed 7 | * arrays 8 | * objects - learn next week 9 | 10 | Immutable - cannot be changed 11 | * strings 12 | * numbers 13 | * booleans 14 | */ 15 | 16 | 17 | let sequence = ['T','A','C','G']; 18 | console.log(sequence);// [ 'T', 'A', 'C', 'G' ] 19 | sequence[0] = 'C'; 20 | console.log(sequence);// [ 'C', 'A', 'C', 'G' ] 21 | 22 | 23 | let name = 'brandon'; 24 | console.log(name);// brandon 25 | name[0] = 'k'; 26 | console.log(name);// brandon 27 | 28 | name = 'krandon'; 29 | console.log(name);// krandon 30 | 31 | 32 | console.log('brandon'.slice(0,2)) 33 | -------------------------------------------------------------------------------- /w1/d4/images/pairs_in_arrays.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/w1/d4/images/pairs_in_arrays.png -------------------------------------------------------------------------------- /w1/d4/images/unique_pairs_in_arrays.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/w1/d4/images/unique_pairs_in_arrays.png -------------------------------------------------------------------------------- /w1/d4/lecture.js: -------------------------------------------------------------------------------- 1 | console.log('good morning!') 2 | -------------------------------------------------------------------------------- /w1/d5/lecture.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/w1/d5/lecture.js -------------------------------------------------------------------------------- /w1/d5/maica-santos-aa01-assessment-practice-coding-problems-temp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "coding-problems", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "test": "mocha" 6 | }, 7 | "license": "ISC", 8 | "dependencies": { 9 | "chai": "^4.3.10", 10 | "mocha": "^10.2.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /w1/d5/maica-santos-aa01-assessment-practice-coding-problems-temp/problems/02-debugging-is-sorted.js: -------------------------------------------------------------------------------- 1 | /* 2 | Your friend is working on a function called isSorted which checks if an 3 | array of numbers is in order, sorted lowest to highest. The function should 4 | return true if the array is in order, and false if it is not. Unfortunately, the 5 | code is not working correctly. Help them fix it! 6 | */ 7 | 8 | function isSorted(nums) { 9 | for (let i = 0; i < nums.length; i++) { 10 | if (nums[i] < nums[i - 1] ) { 11 | // console.log('prev',nums[i-1]) 12 | return false; 13 | } 14 | } 15 | return true; 16 | } 17 | 18 | console.log(isSorted([1])); // true 19 | console.log(isSorted([1, 2, 3, 4, 5])); // true 20 | console.log(isSorted([2, 2, 4, 4])); // true 21 | console.log(isSorted([1, 2, 4, 3, 5, 6])); // false 22 | 23 | /******************** DO NOT MODIFY ANY CODE BELOW THIS LINE *****************/ 24 | module.exports = isSorted; 25 | -------------------------------------------------------------------------------- /w1/d5/maica-santos-aa01-assessment-practice-coding-problems-temp/test/01-string-changer-spec.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const expect = chai.expect; 3 | const stringChanger = require("../problems/01-string-changer"); 4 | 5 | describe("stringChanger", function() { 6 | it("stringChanger('foo', 'capitalize') returns 'Foo'", function () { 7 | expect(stringChanger('foo', 'capitalize')).to.eq('Foo'); 8 | }); 9 | it("stringChanger('foo', 'uppercase') returns 'FOO'", function () { 10 | expect(stringChanger('foo', 'uppercase')).to.eq('FOO'); 11 | }); 12 | it("stringChanger('foo', 'double') returns 'foofoo'", function () { 13 | expect(stringChanger('foo', 'double')).to.eq('foofoo'); 14 | }); 15 | it("stringChanger('foo', 'reverse') returns 'oof'", function () { 16 | expect(stringChanger('foo', 'reverse')).to.eq('oof'); 17 | }); 18 | it("stringChanger('foo', 'unknown') returns 'foo'", function () { 19 | expect(stringChanger('foo', 'unknown')).to.eq('foo'); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /w1/d5/maica-santos-aa01-assessment-practice-coding-problems-temp/test/02-debugging-is-sorted-spec.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const expect = chai.expect; 3 | const isSorted = require("../problems/02-debugging-is-sorted"); 4 | 5 | describe("isSorted", function() { 6 | it("isSorted([1]) returns true", function () { 7 | expect(isSorted([1])).to.be.true; 8 | }); 9 | it("isSorted([1, 2, 3, 4, 5]) returns true", function () { 10 | expect(isSorted([1, 2, 3, 4, 5])).to.be.true; 11 | }); 12 | it("isSorted([2, 2, 4, 4]) returns true", function () { 13 | expect(isSorted([2, 2, 4, 4])).to.be.true; 14 | }); 15 | it("isSorted([1, 2, 4, 3, 5, 6]) returns false", function () { 16 | expect(isSorted([1, 2, 4, 3, 5, 6])).to.be.false; 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /w1/d5/maica-santos-aa01-assessment-practice-coding-problems-temp/test/utils/02-debugging-is-sorted-original.js: -------------------------------------------------------------------------------- 1 | function isSorted(nums) { 2 | for (let i = 0; i < nums.length; i++) { 3 | if (nums[i - 1] < nums[i]) { 4 | return false; 5 | } 6 | } 7 | return true; 8 | } -------------------------------------------------------------------------------- /w1/d5/test.js: -------------------------------------------------------------------------------- 1 | // let num = 100; 2 | // let isBig = num >= 100; 3 | // let isSmall = num < 100; 4 | // console.log(isBig || isSmall); 5 | 6 | 7 | // console.log((true && false) === (!true || !false)) 8 | 9 | // let x = 1; 10 | // x++; 11 | // x + 2; 12 | // console.log(x); 13 | 14 | console.log(1 + 2 * 3); 15 | -------------------------------------------------------------------------------- /w2/d1/lecture.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/w2/d1/lecture.js -------------------------------------------------------------------------------- /w2/d1/pojo_demos/pojo_basics/01-declare_key_values.js: -------------------------------------------------------------------------------- 1 | /*Declare Keys/Values 2 | Given the following declaration of an object, obj below, declare values so 3 | that the print statements output what is expected. Try using both dot and bracket notation. 4 | */ 5 | 6 | const obj = {}; 7 | 8 | // Write your code here. 9 | 10 | // DOT Notation 11 | // obj.firstKey = 'firstValue' 12 | // obj.numeric = 2 13 | // obj.boolean = false 14 | // obj.object = {} 15 | 16 | //Bracket Notion 17 | obj["firstKey"] = "firstVale"; 18 | obj["numeric"] = 2; 19 | obj["boolean"] = false; 20 | obj["object"] = {}; 21 | 22 | // use bracket notation for two word keys 23 | // 'my name' 24 | 25 | // obj['my name'] = 'maica' 26 | 27 | console.log(obj["firstKey"]); // firstValue 28 | console.log(obj["numeric"]); // 2 29 | console.log(obj["boolean"]); // false 30 | console.log(obj["object"]); // {} 31 | // console.log(obj['my name']); 32 | -------------------------------------------------------------------------------- /w2/d1/pojo_demos/pojo_basics/02-delete_keys_values.js: -------------------------------------------------------------------------------- 1 | /* 2 | Delete Keys/Values 3 | Given the object below, delete the key-value pair such that "{}" is printed 4 | when printing the object. 5 | */ 6 | 7 | const obj = { 8 | first: "1", 9 | }; 10 | 11 | // Use the delete key word! works for both dot and bracket notation 12 | // delete obj.first 13 | delete obj["first"]; 14 | 15 | console.log(obj); // {} 16 | -------------------------------------------------------------------------------- /w2/d1/pojo_demos/pojo_basics/03-using_variables_as_keys.js: -------------------------------------------------------------------------------- 1 | /* 2 | Using Variables as keys 3 | Write a function that accepts an object, obj, and a string, str and prints 4 | the value from the object at the key str. 5 | */ 6 | 7 | const obj = { 8 | first: "1", 9 | second: 2, 10 | third: "three", 11 | }; 12 | 13 | const str = "first"; 14 | 15 | const variableAsKey = (obj, str) => { 16 | // Write your code here. 17 | 18 | // We must use bracket notation in this case because dot notation does not work with variables 19 | console.log(obj[str]); 20 | }; 21 | 22 | variableAsKey(obj, str); // "1" 23 | variableAsKey(obj, "second"); // 2 24 | -------------------------------------------------------------------------------- /w2/d1/pojo_demos/pojo_basics/04-dot_vs_bracket_notation.js: -------------------------------------------------------------------------------- 1 | /* 2 | Dot vs Bracket Notation 3 | Given the object below, print out the values corresponding to each key 4 | individually. Try using both dot and bracket notation where they're appropriate. 5 | */ 6 | 7 | const obj = { 8 | "first key": "1", 9 | second: 2, 10 | third_key: "three", 11 | }; 12 | 13 | // Write your solution here. 14 | 15 | // must use bracket notation here because the key is a string of two words 16 | console.log(obj["first key"]); 17 | 18 | // these cases allow for more flexibility. Can use either or in these cases. 19 | console.log(obj.second); 20 | console.log(obj["second"]); 21 | console.log(obj.third_key); 22 | console.log(obj["third_key"]); 23 | -------------------------------------------------------------------------------- /w2/d1/pojo_demos/pojo_basics/05-cat_builder.js: -------------------------------------------------------------------------------- 1 | /* 2 | Cat Builder 3 | Write a function catBuilder(name, color, toys) that returns a cat object object with the corresponding properties. 4 | */ 5 | 6 | function catBuilder(name, color, toys) { 7 | // your code here... 8 | 9 | /* 10 | 11 | Shout out to Varun and Finn! 😎 😎 12 | 13 | 1 liner: 14 | return name === 'Whiskers' || name === 'Nyan' ? { name:name, color:color, toys:toys } : false; 15 | 16 | returning the object setting key val pairs at the same time: 17 | 18 | return { 19 | name: name, 20 | color: color, 21 | toys: toys 22 | }; 23 | */ 24 | 25 | const cat = {}; 26 | 27 | //dot notation 28 | // cat.name = name 29 | // cat.color = color 30 | // cat.toys = toys 31 | 32 | // bracket notation 33 | cat[name] = name; 34 | cat[color] = color; 35 | cat[toys] = toys; 36 | 37 | return cat; 38 | } 39 | 40 | console.log(catBuilder("Whiskers", "black", ["scratching-post", "yarn"])); 41 | // prints: { name: 'Whiskers', color: 'black', toys: ['scratching-post', 'yarn'] } 42 | 43 | console.log(catBuilder("Nyan", "rainbow", ["poptarts"])); 44 | // prints: { name: 'Nyan', color: 'rainbow', toys: [ 'poptarts' ] } 45 | -------------------------------------------------------------------------------- /w2/d1/pojo_demos/pojo_basics/06-check_if_key_is_in_object.js: -------------------------------------------------------------------------------- 1 | /* 2 | Check if key is in object 3 | Write a function includedInObject that accepts an object, obj, and a key 4 | and returns true if that key exists on the object or false otherwise. 5 | */ 6 | 7 | const obj = { 8 | first: "1", 9 | second: 2, 10 | third: "three", 11 | }; 12 | 13 | const includedInObject = (obj, key) => { 14 | // Write your solution here. 15 | 16 | // alternative syntax using 'in' key operator 17 | // if (key in obj) return true 18 | 19 | if (obj[key] !== undefined) return true; 20 | return false; 21 | }; 22 | 23 | console.log(includedInObject(obj, "first")); // true 24 | console.log(includedInObject(obj, "second")); // true 25 | console.log(includedInObject(obj, "fourth")); // false 26 | -------------------------------------------------------------------------------- /w2/d1/pojo_demos/pojo_basics/07-nested_array_of_objects.js: -------------------------------------------------------------------------------- 1 | /* 2 | Nested array of objects 3 | Given the nested array of objects below, write a function, getSecondObjValues, 4 | that prints the value of the second object within each nested sub-array. If there is no second object, print null. 5 | */ 6 | 7 | const nestedArr = [ 8 | [{ a: 1 }, { b: 2 }], 9 | [{ c: 3 }, { d: 4 }, { e: 5 }], 10 | [{ f: 6 }], 11 | [{ g: 7 }, { h: 8 }], 12 | ]; 13 | 14 | const getSecondObjValues = (arr) => { 15 | // iterate through the array of sub arrays 16 | for (let i = 0; i < arr.length; i++) { 17 | // isolate the subArr 18 | let subArr = arr[i]; 19 | // console.log(subArr[1]) 20 | 21 | // index into 'second' object in the subArr 22 | let secondObj = subArr[1]; 23 | 24 | // if the subArr does NOT have a second object in it, return null 25 | if (!secondObj) console.log(null); 26 | 27 | // iterate through the obj using for in loop to dynamically access the keys 28 | for (let key in secondObj) { 29 | // grab the val 30 | let val = secondObj[key]; 31 | 32 | // print it! 33 | console.log(val); 34 | } 35 | } 36 | }; 37 | 38 | getSecondObjValues(nestedArr); // 2 4 null 8 39 | -------------------------------------------------------------------------------- /w2/d1/pojo_demos/pojo_iteration/01-iterate_through_obj.js: -------------------------------------------------------------------------------- 1 | /* 2 | Iterate Through Obj 3 | Write a function printObject(obj) that prints out all key-value pairs of an object. The format should be key - value. 4 | 5 | HINT: use a for loop 6 | */ 7 | 8 | function printObject(obj) { 9 | // your code here... 10 | for (let key in obj) { 11 | // console.log(key) 12 | 13 | 14 | let value = obj[key] 15 | 16 | console.log(key + ' - ' + value) 17 | } 18 | 19 | } 20 | 21 | let bootcamp = { 22 | name: "App Academy", 23 | color: "Red", 24 | population: 120 25 | }; 26 | 27 | printObject(bootcamp); // prints 28 | // name - App Academy 29 | // color - Red 30 | // population - 120 31 | -------------------------------------------------------------------------------- /w2/d1/pojo_demos/pojo_iteration/02-using_Object.keys_I.js: -------------------------------------------------------------------------------- 1 | /* 2 | Using Object.keys I 3 | Given the object below, use Object.keys() to iterate through the object and 4 | print all its values. 5 | */ 6 | 7 | const obj = { 8 | first: "1", 9 | second: 2, 10 | third: "three" 11 | } 12 | 13 | // Write your solution here. 14 | 15 | let keys = Object.keys(obj) 16 | 17 | // console.log(keys) 18 | 19 | for (let i = 0; i < keys.length; i++){ 20 | let key = keys[i] 21 | 22 | console.log(typeof obj[key]) 23 | } 24 | 25 | -------------------------------------------------------------------------------- /w2/d1/pojo_demos/pojo_iteration/03-using_Object.keys_II.js: -------------------------------------------------------------------------------- 1 | /* 2 | Using Object.keys II 3 | Given the object below, use Object.keys() to iterate through the object and 4 | print the key if there are 2 or more "c"s within the value. 5 | */ 6 | 7 | const obj = { 8 | red: "circle", 9 | blue: "square", 10 | green: "hexagon" 11 | } 12 | 13 | // Write your solution here. 14 | let keys = Object.keys(obj) 15 | 16 | for (let key of keys){ 17 | let cCount = 0; 18 | let value = obj[key] 19 | // console.log(value) 20 | for (let char of value) { 21 | // console.log(char) 22 | if(char === 'c') cCount++ 23 | } 24 | // console.log(cCount) 25 | if (cCount >= 2) console.log(key) 26 | 27 | } 28 | 29 | 30 | // Should print "red" 31 | -------------------------------------------------------------------------------- /w2/d1/pojo_demos/pojo_iteration/04-using_Object.values.js: -------------------------------------------------------------------------------- 1 | /* 2 | Using Object.values 3 | Write a function that accepts and object, obj, and uses Object.values to print all values in the object. 4 | */ 5 | 6 | const obj = { 7 | first: "1", 8 | second: 2, 9 | third: "three" 10 | } 11 | 12 | 13 | const printValues = obj => { 14 | // Write your solution here. 15 | 16 | let values = Object.values(obj) 17 | // console.log(values) 18 | 19 | for (let val of values) { 20 | console.log(val) 21 | } 22 | } 23 | 24 | printValues(obj); // "1", 2, "three" 25 | -------------------------------------------------------------------------------- /w2/d1/pojo_demos/pojo_iteration/05-check_if_value_is_in_obj.js: -------------------------------------------------------------------------------- 1 | /* 2 | Check if value is in object 3 | Write a function valInObject that accepts an object, obj, and a value 4 | The function should return true if that value is indeed a value in the object, or false otherwise. 5 | */ 6 | 7 | const obj = { 8 | item1: "jar", 9 | item2: "pot", 10 | item3: "spatula", 11 | item4: "whisk" 12 | } 13 | 14 | const valInObject = (obj, value) => { 15 | // Write your solution here. 16 | for (let key in obj){ 17 | let val = obj[key] 18 | 19 | // console.log(val) 20 | 21 | if (val === value) return true 22 | } 23 | 24 | return false 25 | 26 | } 27 | 28 | console.log(valInObject(obj, "jar")); // true 29 | console.log(valInObject(obj, "pot")); // true 30 | console.log(valInObject(obj, "cup")); // false 31 | console.log(valInObject(obj, "fork")); // false 32 | -------------------------------------------------------------------------------- /w2/d1/pojo_demos/pojo_iteration/06-using_Object.entries.js: -------------------------------------------------------------------------------- 1 | /* 2 | Using Object.entries 3 | Write a function that takes in an object that uses car owners' names as keys 4 | and the car brand they own as values. The function should print the names of the owners whose names are strictly longer than 5 characters and who own a "Honda". 5 | 6 | Note: Use Object.entries to make your life easier! 7 | */ 8 | 9 | const obj = { 10 | Jacky: "Honda", 11 | Ramon: "Kia", 12 | Lexi: "Mercedes", 13 | Eli: "Honda", 14 | Bradley: "Honda", 15 | Cecily: "BMW" 16 | } 17 | 18 | const printOwners = obj => { 19 | // Write your solution here. 20 | 21 | let entries = Object.entries(obj) 22 | 23 | // console.log(entries) 24 | 25 | for (let entry of entries){ 26 | // console.log(entry) 27 | let name = entry[0] 28 | let car = entry[1] 29 | 30 | if(name.length > 5 && car === "Honda") console.log(entry[0]) 31 | } 32 | } 33 | 34 | printOwners(obj); // Bradley 35 | -------------------------------------------------------------------------------- /w2/d1/pojo_demos/pojo_iteration/07-refactoring_iteration.js: -------------------------------------------------------------------------------- 1 | /* 2 | Refactoring Iteration 3 | Given the function below that iterates through an object and prints all values 4 | associated with keys that are vowels using Object.keys(), refactor the code 5 | to use the for...in pattern to iterate through the object. 6 | 7 | 8 | 9 | Key point here is to note how there are multiple ways to iterate through an 10 | object that are interchangeable. Comment out the original function to run your refactored function. 11 | */ 12 | 13 | const obj = { 14 | a: "get", 15 | b: "all", 16 | c: "of", 17 | d: "the", 18 | e: "values" 19 | } 20 | 21 | // const printValues = obj => { 22 | // const vowels = ['a', 'e', 'i', 'o', 'u']; 23 | // for(let key of Object.keys(obj)) { 24 | // if(vowels.indexOf(key) >= 0) { 25 | // console.log(obj[key]); 26 | // } 27 | // } 28 | // } 29 | 30 | const printValuesRefactored = obj => { 31 | // Write your solution here. 32 | const vowels = ['a', 'e', 'i', 'o', 'u']; 33 | for (let key in obj) { 34 | if(vowels.indexOf(key) >= 0) { 35 | console.log(obj[key]); 36 | } 37 | } 38 | } 39 | 40 | // printValues(obj); // get values 41 | printValuesRefactored(obj); // get values 42 | -------------------------------------------------------------------------------- /w2/d2/lecture.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/w2/d2/lecture.js -------------------------------------------------------------------------------- /w2/d3/forOf-vs-forIn.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | //for of 4 | 5 | let numbers = [1,2,3]; 6 | 7 | for(let number of numbers){ 8 | console.log(number); 9 | } 10 | 11 | 12 | let obj = {name:'brandon', age: 28}; 13 | //! cant use for of on object 14 | // for(let ele of obj) { 15 | // console.log(ele); 16 | // } 17 | // TypeError: obj is not iterable 18 | 19 | 20 | // for in 21 | // ! on objects! 22 | for(let key in obj) { 23 | console.log(key);// name | age 24 | } 25 | let array1 = ['HELLO', 'WORLD', true]; 26 | 27 | let array2 = { 28 | 0:'HELLO', 29 | 1:'WORLD', 30 | 2: true, 31 | lengthW: Object.keys(this).length 32 | } 33 | 34 | // console.log(array2[0]);//HELLO 35 | // console.log(array1[0]);//HELLO 36 | console.log(array2.lengthW) 37 | 38 | // for(let index in numbers) { 39 | // console.log(index, typeof index); 40 | // // } 41 | 42 | 43 | // FOR OF ONLY ON ARRAYS 44 | // FOR IN ONLY OBJECTS 45 | -------------------------------------------------------------------------------- /w2/d3/lecture.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/w2/d3/lecture.js -------------------------------------------------------------------------------- /w2/d3/nestedArr-repl.js: -------------------------------------------------------------------------------- 1 | const nestedArr = [ 2 | [ 3 | { a: 1 }, 4 | { b: 2 } 5 | ], 6 | [ 7 | { c: 3 }, 8 | { d: 4 }, 9 | { e: 5 } 10 | ], 11 | [ 12 | { f: 6 } 13 | ], 14 | [ 15 | { g: 7 }, 16 | { h: 8 } 17 | ] 18 | ]; 19 | 20 | const getSecondObjValues = arr => { 21 | // console.log(arr) 22 | for(let i = 0; i < arr.length; i++) { 23 | let subArr = arr[i]; 24 | // console.log(subArr) 25 | if(subArr[1]) { 26 | let obj = subArr[1] 27 | console.log(obj) 28 | for(let key in obj) { 29 | let value = obj[key] 30 | // console.log(value) 31 | } 32 | } else { 33 | console.log(null) 34 | } 35 | } 36 | } 37 | 38 | getSecondObjValues(nestedArr); // 2 4 null 8 39 | -------------------------------------------------------------------------------- /w2/d4/lecture.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | let arr = ['a','e','i','a', 'o','u', 'z','y']; 7 | 8 | let vowels = 'aeiou' 9 | const result = arr.reduce((obj, letter) => { 10 | 11 | if(vowels.includes(letter)) { 12 | if (obj[letter]) { 13 | obj[letter]++; 14 | } else { 15 | obj[letter] = 1; 16 | } 17 | } 18 | return obj; 19 | },{}); 20 | 21 | 22 | console.log(result); 23 | let obj2 = {}; 24 | obj2[1] = 1; 25 | console.log(obj2); 26 | obj2[1]++ 27 | console.log(obj2); 28 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/build_trigger.md: -------------------------------------------------------------------------------- 1 | This file is used to manually trigger the build process. It is here to provide 2 | a defined place to commit a trivial change. It may be ignored by students. 3 | 4 | To use, simply add the date and time below and commit to branch->staging->master 5 | as normal. 6 | 7 | 3/6/23 3:57 pm 8 | 09/01/2023 2:30pm ET 9 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "callbacks-solution", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha", 11 | "test-with-json": "mocha --reporter json" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "dependencies": { 17 | "chai": "^4.2.0", 18 | "chai-spies": "^1.0.0", 19 | "mocha": "^6.2.2" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/problems/00-sum-forEach.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function `sumForEach(arr)` that accepts an array as an arg. 3 | The function should return the total sum of all values in the array. 4 | 5 | Solve this using Array's `forEach()` method. 6 | 7 | Examples: 8 | 9 | console.log(sumForEach([4, 3, -1, 10])); // 16 10 | console.log(sumForEach([6, 7, 2])); // 15 11 | console.log(sumForEach([])); // 0 12 | */ 13 | 14 | let sumForEach = function(arr) { 15 | //!!START 16 | let sum = 0; 17 | 18 | arr.forEach(function(el) { 19 | sum += el; 20 | }); 21 | 22 | return sum; 23 | //!!END 24 | }; 25 | 26 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 27 | 28 | try { 29 | module.exports = sumForEach; 30 | } catch (e) { 31 | module.exports = null; 32 | } 33 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/problems/01-avg-val-forEach.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function `avgVal(arr)` that accepts an array as an arg. The function 3 | should return the average of all values in the array. If the array is empty, 4 | it should return `null`. 5 | 6 | Solve this using Array's `forEach()` method. 7 | 8 | Examples: 9 | 10 | console.log(avgVal([5, 10])); // 7.5 11 | console.log(avgVal([3, 7, 2, 1, 2])); // 3 12 | console.log(avgVal([])); // null 13 | 14 | */ 15 | 16 | let avgVal = function(arr) { 17 | //!!START 18 | if (arr.length === 0) { 19 | return null; 20 | } 21 | 22 | let sum = 0; 23 | arr.forEach(function(el) { 24 | sum += el; 25 | }); 26 | 27 | return sum / arr.length; 28 | //!!END 29 | }; 30 | 31 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 32 | 33 | try { 34 | module.exports = avgVal; 35 | } catch (e) { 36 | module.exports = null; 37 | } 38 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/problems/02-tripler-map.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function `tripler(nums)` that takes in an array as an arg. The function 3 | should return a new array containing three times every number of the original 4 | array. 5 | 6 | Solve this using Array's `map()` method. 7 | 8 | Examples: 9 | 10 | console.log(tripler([2, 7, 4])); // [ 6, 21, 12 ] 11 | console.log(tripler([-5, 10, 0, 11])); // [ -15, 30, 0, 33 ] 12 | */ 13 | 14 | let tripler = function(nums) { 15 | //!!START 16 | let newNums = nums.map(function(num) { 17 | return num * 3; 18 | }); 19 | 20 | return newNums; 21 | //!!END 22 | }; 23 | 24 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 25 | 26 | try { 27 | module.exports = tripler; 28 | } catch (e) { 29 | module.exports = null; 30 | } 31 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/problems/03-long-words-filter.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Write a function `longWords(words)` that takes in an array of words. 4 | The function should return an array containing only the words that are longer 5 | than 5 characters. 6 | 7 | Solve this using Array's `filter()` method. 8 | 9 | Examples: 10 | 11 | console.log(longWords(['bike', 'skateboard','scooter', 'moped'])); // [ 'skateboard', 'scooter' ] 12 | console.log(longWords(['couscous', 'soup', 'ceviche', 'solyanka' ,'taco'])); // [ 'couscous', 'ceviche', 'solyanka' ] 13 | 14 | */ 15 | 16 | let longWords = function(words) { 17 | //!!START 18 | return words.filter(function(word) { 19 | return word.length > 5; 20 | }); 21 | //!!END 22 | }; 23 | 24 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 25 | 26 | try { 27 | module.exports = longWords; 28 | } catch (e) { 29 | module.exports = null; 30 | } 31 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/problems/04-remove-e-words-filter.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function `removeEWords(sentence)` that accepts a sentence string as an 3 | arg. The function should return a new string, containing only the words that 4 | don't have the letter "e" in them. 5 | 6 | Solve this using Array's `filter()` method. 7 | 8 | Examples: 9 | 10 | console.log(removeEWords('What time is it everyone?')); // 'What is it' 11 | console.log(removeEWords('Enter the building')); // 'building' 12 | 13 | */ 14 | 15 | let removeEWords = function(sentence) { 16 | //!!START 17 | let words = sentence.split(' '); 18 | 19 | let filtered = words.filter(function(word) { 20 | return !word.toLowerCase().includes('e'); 21 | }); 22 | 23 | return filtered.join(' '); 24 | //!!END 25 | }; 26 | 27 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 28 | 29 | try { 30 | module.exports = removeEWords; 31 | } catch (e) { 32 | module.exports = null; 33 | } 34 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/problems/06-sum-reduce.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Write a function `sumWithReduce(nums)` that takes in an array of numbers. 4 | The function should return the total sum of all numbers in the array. 5 | 6 | Solve this using Array's `reduce()` method. 7 | 8 | Examples: 9 | 10 | console.log(sumWithReduce([10, 3, 5, 2])); // 20 11 | console.log(sumWithReduce([])); // 0 12 | 13 | */ 14 | 15 | let sumWithReduce = function(nums) { 16 | //!!START 17 | let total = nums.reduce(function(sum, num) { 18 | return sum + num; 19 | }, 0); 20 | 21 | return total; 22 | //!!END 23 | }; 24 | 25 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 26 | 27 | try { 28 | module.exports = sumWithReduce; 29 | } catch (e) { 30 | module.exports = null; 31 | } 32 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/problems/07-max-reduce.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Write a function `maxWithReduce(nums)` that takes in an array of numbers. 4 | The function should return the largest number of the array. 5 | 6 | You can assume that the array will not be empty. 7 | 8 | Solve this using Array's `reduce()` method. 9 | 10 | Examples: 11 | 12 | console.log(maxWithReduce([4, 6, 3, 5, 42, 4])); // 42 13 | console.log(maxWithReduce([-2, -3, -7, 3])); // 3 14 | 15 | */ 16 | 17 | let maxWithReduce = function(nums) { 18 | //!!START 19 | return nums.reduce(function(max, num) { 20 | if (num > max) { 21 | return num; 22 | } else { 23 | return max; 24 | } 25 | }); 26 | //!!END 27 | }; 28 | 29 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 30 | 31 | try { 32 | module.exports = maxWithReduce; 33 | } catch (e) { 34 | module.exports = null; 35 | } 36 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/problems/08-product-reduce.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Write a function `productWithReduce(nums)` that takes in an array of numbers. 4 | The function should return the total product of multiplying all numbers of the 5 | array together. 6 | 7 | You can assume that `nums` will not be an empty array. 8 | 9 | Solve this using Array's `reduce()` method. 10 | 11 | Examples: 12 | 13 | console.log(productWithReduce([10, 3, 5, 2])); // 300 14 | console.log(productWithReduce([4, 3])); // 12 15 | 16 | */ 17 | 18 | let productWithReduce = function(nums) { 19 | //!!START 20 | return nums.reduce(function(product, num) { 21 | return product * num; 22 | }); 23 | //!!END 24 | } 25 | 26 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 27 | 28 | try { 29 | module.exports = productWithReduce; 30 | } catch (e) { 31 | module.exports = null; 32 | } 33 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/problems/09-snake-to-camel-map.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function `snakeToCamel` that takes in a snake_cased string and returns a 3 | PascalCased version of the string. snake_case is where each word is separated 4 | with underscores(`_`). PascalCase is a string where the first char of each word 5 | is capital, all other chars lowercase. 6 | 7 | Solve this using `array.map()`. 8 | 9 | Examples: 10 | 11 | console.log(snakeToCamel('snakes_go_hiss')); // 'SnakesGoHiss' 12 | console.log(snakeToCamel('say_hello_world')); // 'SayHelloWorld' 13 | console.log(snakeToCamel('app_academy_is_cool')); // 'AppAcademyIsCool' 14 | console.log(snakeToCamel('APp_ACADEMY_iS_cOol')); // 'AppAcademyIsCool' 15 | 16 | */ 17 | 18 | function snakeToCamel(str) { 19 | //!!START 20 | let words = str.split('_'); 21 | let newWords = words.map(function(word) { 22 | return word[0].toUpperCase() + word.slice(1).toLowerCase(); 23 | }); 24 | return newWords.join(''); 25 | //!!END 26 | } 27 | 28 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 29 | 30 | try { 31 | module.exports = snakeToCamel; 32 | } catch (e) { 33 | module.exports = null; 34 | } 35 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/problems/10-yeller-map.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function `yeller(words)` that takes in an array of words. 3 | The function should return a new array where each element of the original array 4 | is yelled. 5 | 6 | Solve this using Array's `map()` method. 7 | 8 | Examples: 9 | 10 | console.log(yeller(['hello', 'world'])); // [ 'HELLO!', 'WORLD!' ] 11 | console.log(yeller(['kiwi', 'orange', 'mango'])); // [ 'KIWI!', 'ORANGE!', 'MANGO!' ] 12 | 13 | */ 14 | 15 | let yeller = function(words) { 16 | //!!START 17 | return words.map(function(word) { 18 | return word.toUpperCase() + "!"; 19 | }); 20 | //!!END 21 | }; 22 | 23 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 24 | 25 | try { 26 | module.exports = yeller; 27 | } catch (e) { 28 | module.exports = null; 29 | } 30 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/problems/13-unique.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function `unique` that accepts an array as an argument. The function 3 | should return a new array containing elements of the input array, without 4 | duplicates. 5 | Solve this using Array's `forEach()`, `map()`, `filter()` **OR** `reduce()` 6 | methods. 7 | Examples: 8 | console.log(unique([1, 1, 2, 3, 3])); // [1, 2, 3] 9 | console.log(unique([11, 7, 8, 10, 8, 7, 7])); // [11, 7, 8, 10] 10 | console.log(unique(['a', 'b', 'c', 'b'])); // ['a', 'b', 'c'] 11 | */ 12 | 13 | let unique = function(array) { 14 | //!!START 15 | let uniques = []; 16 | array.forEach(function(el) { 17 | if (!uniques.includes(el)) { 18 | uniques.push(el); 19 | } 20 | }); 21 | return uniques; 22 | //!!END 23 | }; 24 | 25 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 26 | 27 | try { 28 | module.exports = unique; 29 | } catch (e) { 30 | module.exports = null; 31 | } 32 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/problems/18-two-d-product.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function `twoDimensionalProduct(array)` that takes in a 2D array of 3 | numbers as an argument. The function should return the total product of all 4 | numbers multiplied together. 5 | 6 | Solve this using Array's `forEach()`, `map()`, `filter()` **OR** `reduce()` 7 | methods. 8 | 9 | Examples: 10 | 11 | 12 | let arr1 = [ 13 | [6, 4], 14 | [5], 15 | [3, 1] 16 | ]; 17 | console.log(twoDimensionalProduct(arr1)); // 360 18 | 19 | let arr2 = [ 20 | [11, 4], 21 | [2] 22 | ]; 23 | console.log(twoDimensionalProduct(arr2)); // 88 24 | */ 25 | 26 | let twoDimensionalProduct = function(arr) { 27 | //!!START 28 | let product = 1; 29 | 30 | arr.forEach(function(subArr) { 31 | subArr.forEach(function(num) { 32 | product *= num; 33 | }); 34 | }); 35 | 36 | return product; 37 | //!!END 38 | }; 39 | 40 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 41 | 42 | try { 43 | module.exports = twoDimensionalProduct; 44 | } catch (e) { 45 | module.exports = null; 46 | } 47 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/00-sum-forEach-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const sumForEach = require('../problems/00-sum-forEach'); 4 | 5 | describe('sumForEach()', function () { 6 | it('should add all the numbers in the given array with Array\'s forEach method', function () { 7 | assert.equal(sumForEach([4, 3, -1, 10]), 16); 8 | assert.equal(sumForEach([6, 7, 2]), 15); 9 | assert.equal(sumForEach([]), 0); 10 | }); 11 | }); 12 | 13 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/01-avg-val-forEach-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const avgVal = require('../problems/01-avg-val-forEach'); 4 | 5 | describe('avgVal()', function () { 6 | it('should take the average value from the array with Array\'s forEach method', function () { 7 | assert.equal(avgVal([5, 10]), 7.5); 8 | assert.equal(avgVal([3, 7, 2, 1, 2]), 3); 9 | assert.equal(avgVal([]), null); 10 | }); 11 | }); 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/02-tripler-map-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const tripler = require('../problems/02-tripler-map'); 4 | 5 | describe('tripler()', function () { 6 | it('should return an array of all the numbers multiplied by 3 in the given array with Array\'s map method', function () { 7 | assert.deepStrictEqual(tripler([2, 7, 4]), [ 6, 21, 12 ]); 8 | assert.deepStrictEqual(tripler([-5, 10, 0, 11]), [ -15, 30, 0, 33 ]); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/03-long-words-filter-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const longWords = require('../problems/03-long-words-filter'); 4 | 5 | describe('longWords()', function () { 6 | it('should return an array with all words over 5 characters in the given array with Array\'s filter method', function () { 7 | assert.deepStrictEqual(longWords(['bike', 'skateboard', 'scooter', 'moped']), [ 'skateboard', 'scooter' ]); 8 | assert.deepStrictEqual(longWords(['couscous', 'soup', 'ceviche', 'solyanka', 'taco']), [ 'couscous', 'ceviche', 'solyanka' ]); 9 | }); 10 | }); 11 | 12 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/04-remove-e-words-filter-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const removeEWords = require('../problems/04-remove-e-words-filter'); 4 | 5 | describe('removeEWords()', function () { 6 | it('should return a string of words without the letter "e" with Array\'s filter method', function () { 7 | assert.equal(removeEWords('What time is it everyone?'), 'What is it'); 8 | assert.equal(removeEWords('Enter the building'), 'building'); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/05-choosey-endings-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const chooseyEndings = require('../problems/05-choosey-endings-filter'); 4 | 5 | describe('chooseyEndings()', function () { 6 | it('should return an array of strings only with the given ending with Array\'s filter method', function () { 7 | assert.deepStrictEqual( 8 | chooseyEndings(['family', 'hound', 'catalyst', 'fly', 'timidly', 'bond'], 'ly'), 9 | [ 'family', 'fly', 'timidly' ] 10 | ); 11 | 12 | assert.deepStrictEqual( 13 | chooseyEndings(['family', 'hound', 'catalyst', 'fly', 'timidly', 'bond'], 'nd'), 14 | [ 'hound', 'bond' ] 15 | ); 16 | 17 | assert.deepStrictEqual( 18 | chooseyEndings(['simplicity', 'computer', 'felicity'], 'icity'), 19 | [ 'simplicity', 'felicity' ] 20 | ); 21 | 22 | assert.deepStrictEqual( 23 | chooseyEndings(['simplicity', 'computer', 'felicity'], 'ily'), 24 | [ ] 25 | ); 26 | 27 | assert.deepStrictEqual( 28 | chooseyEndings(17, 'ily'), 29 | [] 30 | ); 31 | }); 32 | }); 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/06-sum-reduce-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const sumWithReduce = require('../problems/06-sum-reduce'); 4 | 5 | describe('sumWithReduce()', function() { 6 | it('should add all the numbers in the given array with Array\'s reduce method', function() { 7 | assert.equal(sumWithReduce([10, 3, 5, 2]), 20); 8 | assert.equal(sumWithReduce([]), 0); 9 | }); 10 | }); -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/07-max-reduce-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const maxWithReduce = require('../problems/07-max-reduce'); 4 | 5 | describe('maxWithReduce()', function () { 6 | it('should return the max number in the given array using Array\'s reduce method', function () { 7 | assert.equal(maxWithReduce([4, 6, 3, 5, 42, 4]), 42); 8 | assert.equal(maxWithReduce([-2, -3, -7, 3]), 3); 9 | }); 10 | }); 11 | 12 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/08-product-reduce-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const productWithReduce = require('../problems/08-product-reduce'); 4 | 5 | describe('productWithReduce()', function () { 6 | it('should multiply all the numbers in the given array with Array\'s reduce method', function () { 7 | assert.equal(productWithReduce([10, 3, 5, 2]), 300); 8 | assert.equal(productWithReduce([4, 3]), 12); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/09-snake-to-camel-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const snakeToCamel = require('../problems/09-snake-to-camel-map'); 4 | 5 | describe('snakeToCamel()', function () { 6 | it('should turn the string from snake case to camel case using Array\'s map method', function () { 7 | assert.equal(snakeToCamel('snakes_go_hiss'), 'SnakesGoHiss'); 8 | assert.equal(snakeToCamel('say_hello_world'), 'SayHelloWorld'); 9 | assert.equal(snakeToCamel('app_academy_is_cool'), 'AppAcademyIsCool'); 10 | assert.equal(snakeToCamel('APp_ACADEMY_iS_cOol'), 'AppAcademyIsCool'); 11 | }); 12 | }); 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/10-yeller-map-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const yeller = require('../problems/10-yeller-map'); 4 | 5 | describe('yeller()', function () { 6 | it('should turn all the elements in the given array uppercase and imperative using Array\'s map method', function () { 7 | assert.deepStrictEqual(yeller(['hello', 'world']), [ 'HELLO!', 'WORLD!' ]); 8 | assert.deepStrictEqual(yeller(['kiwi', 'orange', 'mango']), [ 'KIWI!', 'ORANGE!', 'MANGO!' ]); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/11-has-three-vowels-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const hasThreeVowels = require('../problems/11-has-three-vowels'); 4 | 5 | describe('hasThreeVowels()', function () { 6 | it('should return true if the given string has three different vowels, else false', function () { 7 | assert.equal(hasThreeVowels('delicious'), true); 8 | assert.equal(hasThreeVowels('bootcamp prep'), true); 9 | assert.equal(hasThreeVowels('bootcamp'), false); 10 | assert.equal(hasThreeVowels('dog'), false); 11 | assert.equal(hasThreeVowels('go home'), false); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/12-longest-word-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const longestWord = require('../problems/12-longest-word'); 4 | 5 | describe('longestWord()', function () { 6 | it('should return the longest word in the given string', function () { 7 | assert.equal(longestWord('where did everyone go'), 'everyone'); 8 | assert.equal(longestWord('prefer simplicity over complexity'), 'simplicity'); 9 | assert.equal(longestWord(''), ''); 10 | }); 11 | }); 12 | 13 | 14 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/13-unique-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const unique = require('../problems/13-unique'); 4 | 5 | describe('unique()', function () { 6 | it('should return an array of unique values with Array\'s map method', function () { 7 | assert.deepStrictEqual(unique([1, 1, 2, 3, 3]), [1, 2, 3]); 8 | assert.deepStrictEqual(unique([11, 7, 8, 10, 8, 7, 7]), [11, 7, 8, 10]); 9 | assert.deepStrictEqual(unique(['a', 'b', 'c', 'b']), ['a', 'b', 'c']); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/14-shortest-word-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const shortestWord = require('../problems/14-shortest-word'); 4 | 5 | describe('shortestWord()', function () { 6 | it('should return the shortest word in the given string', function () { 7 | assert.equal(shortestWord('what a wonderful life'), 'a'); 8 | assert.equal(shortestWord('the quick brown fox jumps'), 'fox') 9 | assert.equal(shortestWord('do what you enjoy'), 'do') 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/15-choose-primes-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const choosePrimes = require('../problems/15-choose-primes'); 4 | 5 | describe('choosePrimes()', function () { 6 | it('should return an array of prime numbers', function () { 7 | assert.deepStrictEqual(choosePrimes([36, 48, 9, 13, 19]), [ 13, 19 ]); 8 | assert.deepStrictEqual(choosePrimes([5, 6, 4, 11, 2017]), [ 5, 11, 2017 ]); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/16-hipsterfy-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const hipsterfy = require('../problems/16-hipsterfy'); 4 | 5 | describe('hipsterfy()', function () { 6 | it('should return the string with the last vowel of every word removed', function () { 7 | assert.equal(hipsterfy('When should everyone wake up?'), 'Whn shold everyon wak p?'); 8 | assert.equal(hipsterfy('get ready for our bootcamp'), 'gt redy fr or bootcmp'); 9 | assert.equal(hipsterfy('panthers are great animals'), 'panthrs ar gret animls'); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/17-repeating-translate-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const repeatingTranslate = require('../problems/17-repeating-translate'); 4 | 5 | describe('repeatingTranslate()', function () { 6 | it('should return a new string that is the given string translated using the rules provided', function () { 7 | assert.equal(repeatingTranslate("we like to go running fast"), "we likelike to go runninging fastast"); 8 | assert.equal(repeatingTranslate("he cannot find the trash"), "he cannotot findind thethe trashash"); 9 | assert.equal(repeatingTranslate("pasta is my favorite dish"), "pastapasta is my favoritefavorite dishish"); 10 | assert.equal(repeatingTranslate("her family flew to France"), "herer familyily flewew to FranceFrance"); 11 | }); 12 | }); 13 | 14 | 15 | -------------------------------------------------------------------------------- /w2/solutions/advanced-array-methods/advanced-array/test/18-two-d-product-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | const twoDimensionalProduct = require('../problems/18-two-d-product'); 4 | 5 | describe('twoDimensionalProduct()', function () { 6 | it('should return the product of all the elements of all the nested arrays in the given array', function () { 7 | let arr1 = [ 8 | [6, 4], 9 | [5], 10 | [3, 1] 11 | ]; 12 | assert.equal(twoDimensionalProduct(arr1), 360); 13 | 14 | let arr2 = [ 15 | [11, 4], 16 | [2] 17 | ]; 18 | assert.equal(twoDimensionalProduct(arr2), 88); 19 | }); 20 | }); 21 | 22 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/README.md: -------------------------------------------------------------------------------- 1 | # Callback Problems 2 | 3 | It's time to get some practice using callbacks! 4 | 5 | Complete the problems in the order specified. 6 | 7 | To run the tests for the above problems you will need to unzip the file you 8 | downloaded. 9 | 10 | To get started, use the following commands: 11 | 12 | 1. `cd` into the project directory 13 | 2. `npm install` to install any dependencies 14 | 3. `npm test` to run the test cases 15 | 16 | The `npm test` command will run all the tests. If you have any trouble with this 17 | don't hesitate to ask a TA for help! 18 | 19 | P.S. You may notice the `package.json`/`package-lock.json` files and 20 | `node_modules` directory. You do not need to edit any of those contents. Those 21 | files are what we use to package the project and create the test cases. 22 | 23 | When you finish your project, don't forget to add your project to your Github! 24 | 25 | 1. Initialize the local directory 26 | 2. Add and commit your project 27 | 3. Push the project to the repo you created 28 | 29 | - Here are the docs for references [GitHub Docs][GitHub Docs] 30 | 31 | [GitHub Docs]: https://docs.github.com/en/free-pro-team@latest/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/build_trigger.md: -------------------------------------------------------------------------------- 1 | This file is used to manually trigger the build process. It is here to provide 2 | a defined place to commit a trivial change. It may be ignored by students. 3 | 4 | To use, simply add the date and time below and commit to branch->staging->master 5 | as normal. 6 | 7 | 8/3/23 3:52pm ET 8 | 09/01/2023 2:30pm ET 9 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/naughty_list.md: -------------------------------------------------------------------------------- 1 | pt-split/ -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "callbacks-solution", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha", 11 | "test-with-json": "mocha --reporter json" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "dependencies": { 17 | "chai": "^4.2.0", 18 | "chai-spies": "^1.0.0", 19 | "mocha": "^6.2.2" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/problems/01-my-for-each.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Write a function `myForEach` that accepts an array and a callback as arguments. 3 | The function should call the callback on each element of the array, passing in the 4 | element, index, and array itself. The function does not need to return any value. 5 | 6 | Do not use the built in Array.forEach. 7 | 8 | Examples: 9 | 10 | myForEach(['a', 'b', 'c'], function (el, i) { 11 | console.log(el + ' is at index ' + i); 12 | }); // prints 13 | // a is at index 0 14 | // b is at index 1 15 | // c is at index 2 16 | 17 | let test = []; 18 | myForEach(['laika', 'belka'], function (el) { 19 | test.push(el.toUpperCase()); 20 | }); 21 | console.log(test); // ['LAIKA', 'BELKA'] 22 | *******************************************************************************/ 23 | 24 | function myForEach(array, cb) { 25 | //!!START 26 | for (let i = 0; i < array.length; i++) { 27 | let el = array[i]; 28 | cb(el, i, array); 29 | } 30 | //!!END 31 | } 32 | 33 | /*****************DO NOT MODIFY ANYTHING UNDER THIS LINE**********************/ 34 | try { 35 | module.exports = myForEach; 36 | } catch(e) { 37 | return null; 38 | } 39 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/problems/02-my-map.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Write a function `myMap` that accepts an array and a callback as arguments. 3 | The function return an array of new elements obtained by calling the callback on 4 | each element of the array, passing in the element. 5 | 6 | Do not use the built in Array.map 7 | 8 | // Examples 9 | 10 | let result1 = myMap([100, 25, 81, 64], Math.sqrt); 11 | console.log(result1); // [ 10, 5, 9, 8 ] 12 | 13 | let result2 = myMap(['run', 'Forrest'], function (el) { 14 | return el.toUpperCase() + '!'; 15 | }); 16 | console.log(result2); // [ 'RUN!', 'FORREST!' ] 17 | *******************************************************************************/ 18 | 19 | function myMap(array, cb) { 20 | //!!START 21 | let mapped = []; 22 | for (let i = 0; i < array.length; i++) { 23 | let ele = array[i]; 24 | mapped.push(cb(ele)); 25 | } 26 | return mapped; 27 | //!!END 28 | } 29 | 30 | /*****************DO NOT MODIFY ANYTHING UNDER THIS LINE**********************/ 31 | try { 32 | module.exports = myMap; 33 | } catch(e) { 34 | return null; 35 | } 36 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/problems/03-multi-map.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Write a function `multiMap` that accepts a value, a number n, and a callback. 3 | The function should return the new value that results from running the original value 4 | through the callback n times. 5 | 6 | Examples: 7 | 8 | let result1 = multiMap(7, 2, function(n) { 9 | return n * 10; 10 | }); 11 | console.log(result1); // 700 12 | 13 | let result2 = multiMap(7, 3, function(n) { 14 | return n * 10; 15 | }); 16 | console.log(result2); // 7000 17 | 18 | let result3 = multiMap("hi", 5, function(s) { 19 | return s + "!"; 20 | }); 21 | console.log(result3); // hi!!!!! 22 | *******************************************************************************/ 23 | 24 | function multiMap(val, n, cb) { 25 | //!!START 26 | for (let i = 0; i < n; i++) { 27 | val = cb(val); 28 | } 29 | 30 | return val; 31 | //!!END 32 | } 33 | 34 | /*****************DO NOT MODIFY ANYTHING UNDER THIS LINE**********************/ 35 | try { 36 | module.exports = multiMap; 37 | } catch(e) { 38 | return null; 39 | } 40 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/problems/14-map-mutator.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Write a function `mapMutator` that accepts an array and a callback as arguments. 3 | The function should pass each element and index into the callback and use the result 4 | to overwrite elements of the original array, mutating the array. 5 | 6 | Examples: 7 | 8 | let arr1 = [4, 2, 6, 5]; 9 | mapMutator(arr1, function (el) { 10 | return el * 2; 11 | }); 12 | console.log(arr1); // [ 8, 4, 12, 10 ] 13 | 14 | let arr2 = [8, 9, 10]; 15 | mapMutator(arr2, function (el, i) { 16 | return el * i; 17 | }); 18 | console.log(arr2); // [ 0, 9, 20 ] 19 | *******************************************************************************/ 20 | 21 | function mapMutator(array, cb) { 22 | //!!START 23 | for (let i = 0; i < array.length; i++) { 24 | array[i] = cb(array[i], i, array); 25 | } 26 | //!!END 27 | } 28 | 29 | /*****************DO NOT MODIFY ANYTHING UNDER THIS LINE**********************/ 30 | try { 31 | module.exports = mapMutator; 32 | } catch(e) { 33 | return null; 34 | } 35 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/problems/19-greater-callback-value.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Write a function `greaterCallbackValue` that accepts a value and two callbacks 3 | as arguments. The function should pass the value to both callbacks and return the 4 | result of the callback that is greater. 5 | 6 | Examples: 7 | 8 | let doubler = function (n) { 9 | return 2 * n; 10 | } 11 | 12 | let squarer = function (n) { 13 | return n * n; 14 | } 15 | 16 | console.log(greaterCallbackValue(5, doubler, squarer)); // 25 17 | console.log(greaterCallbackValue(1, doubler, squarer)); // 2 18 | console.log(greaterCallbackValue(9, Math.sqrt, doubler)); // 18 19 | *******************************************************************************/ 20 | 21 | function greaterCallbackValue(val, cb1, cb2) { 22 | //!!START 23 | let res1 = cb1(val); 24 | let res2 = cb2(val); 25 | 26 | if (res1 > res2) { 27 | return res1; 28 | } else { 29 | return res2; 30 | } 31 | //!!END 32 | } 33 | 34 | /*****************DO NOT MODIFY ANYTHING UNDER THIS LINE**********************/ 35 | try { 36 | module.exports = greaterCallbackValue; 37 | } catch (e) { 38 | return null; 39 | } 40 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/pt-split/part-1.md: -------------------------------------------------------------------------------- 1 | # Callbacks Project - Part 1 2 | 3 | In this project, you will be using your knowledge of callbacks to solve 4 | programming problems. 5 | 6 | In this part, you will be tackling the first 6 problems: 7 | 8 | - `01-my-for-each` 9 | - `02-my-map` 10 | - `03-multi-map` 11 | - `04-my-filter` 12 | - `05-selective-map` 13 | - `06-reject` 14 | 15 | These problems will involve you writing a function that takes a callback 16 | function. Think through the process carefully before starting your solution. 17 | Use Polya's Problem-Solving Framework and write down your notes as 18 | comments in the file before you type a single line of code. 19 | 20 | If you finish early, take some time to try to refine your answers or solve them 21 | another way. Be prepared to discuss your solutions. 22 | 23 | In addition to the prompts available at the top of each file, Mocha specs are 24 | provided to test your work. 25 | 26 | To get started, use the following commands: 27 | 28 | ```shell 29 | cd 30 | npm install 31 | npm test 32 | ``` 33 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/pt-split/part-2.md: -------------------------------------------------------------------------------- 1 | # Callbacks Project - Part 2 2 | 3 | In this project, you will continue using your knowledge of callbacks to solve 4 | programming problems. 5 | 6 | In this part, you will be tackling the next 6 problems: 7 | 8 | - `07-my-some` 9 | - `08-count` 10 | - `09-chain-map` 11 | - `10-my-every` 12 | - `11-and-select` 13 | - `12-exactly` 14 | 15 | These problems will involve you writing a function that takes a callback 16 | function. Think through the process carefully before starting your solution. 17 | If you finish early, take some time to try to refine your answers or solve them 18 | another way. Be prepared to discuss your solutions. 19 | 20 | Don't forget to run the Mocha to test your solutions. 21 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/pt-split/part-3.md: -------------------------------------------------------------------------------- 1 | # Callbacks Project - Part 3 2 | 3 | In this project, you will continue using your knowledge of callbacks to solve 4 | programming problems. 5 | 6 | In this part, you will be tackling the next 6 problems: 7 | 8 | - `13-min-value-callback` 9 | - `14-map-mutator` 10 | - `15-sentence-mapper` 11 | - `16-suffix-cipher` 12 | - `17-xor-select` 13 | - `18-one` 14 | 15 | These problems will involve you writing a function that takes a callback 16 | function. Think through the process carefully before starting your solution. 17 | If you finish early, take some time to try to refine your answers or solve them 18 | another way. Be prepared to discuss your solutions. 19 | 20 | Don't forget to run the Mocha to test your solutions. 21 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/pt-split/part-4.md: -------------------------------------------------------------------------------- 1 | # Callbacks Project - Part 4 2 | 3 | In this project, you will continue using your knowledge of callbacks to solve 4 | programming problems. 5 | 6 | In this part, you will be tackling the last 6 problems: 7 | 8 | - `19-greater-callback-value` 9 | - `20-none` 10 | - `21-at-most` 11 | - `22-first-index` 12 | - `23-alternating-map` 13 | - `24-my-simple-reduce` 14 | 15 | These will be the most challenging yet! Don't forget to carefully plan out 16 | your approach to the problem before starting your solution. If you finish early, 17 | take some time to try to refine your answers or solve them another way. Be 18 | prepared to discuss your solutions. 19 | 20 | Don't forget to run the Mocha to test your solutions. 21 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/01-my-for-each-test.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const spies = require("chai-spies"); 3 | const expect = chai.expect; 4 | chai.use(spies); 5 | 6 | const myForEach = require("../problems/01-my-for-each.js"); 7 | 8 | describe("myForEach", function() { 9 | it("should mimic the built-in Array.forEach", function() { 10 | let test = []; 11 | myForEach(['laika', 'belka'], function (el) { 12 | test.push(el.toUpperCase()); 13 | }); 14 | expect(test).to.eql(['LAIKA', 'BELKA']); 15 | }); 16 | 17 | it("should not call the built-in Array.forEach", function() { 18 | const forEachSpy = chai.spy.on(Array.prototype, "forEach"); 19 | myForEach(['laika', 'belka'], function () {}); 20 | expect(forEachSpy).to.have.not.been.called(); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/02-my-map-test.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const spies = require("chai-spies"); 3 | const expect = chai.expect; 4 | chai.use(spies); 5 | 6 | const myMap = require("../problems/02-my-map.js"); 7 | 8 | describe("myMap", function() { 9 | it("should mimic the built-in Array.map", function() { 10 | let result1 = myMap([100, 25, 81, 64], Math.sqrt); 11 | expect(result1).to.eql([ 10, 5, 9, 8 ]); 12 | 13 | let result2 = myMap(["run", "Forrest"], function(el) { 14 | return el.toUpperCase() + "!"; 15 | }); 16 | expect(result2).to.eql([ 'RUN!', 'FORREST!' ]); 17 | }); 18 | 19 | it("should not call the built-in Array.map", function() { 20 | const mapSpy = chai.spy.on(Array.prototype, "map"); 21 | myMap([100, 25, 81, 64], Math.sqrt); 22 | expect(mapSpy).to.have.not.been.called(); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/03-multi-map-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const multiMap = require("../problems/03-multi-map.js"); 3 | 4 | describe("multiMap", function() { 5 | it("should return the new value that results from running the original value through the callback n times", function() { 6 | let result1 = multiMap(7, 2, function(n) { 7 | return n * 10; 8 | }); 9 | assert.equal(result1, 700); 10 | 11 | let result2 = multiMap(7, 3, function(n) { 12 | return n * 10; 13 | }); 14 | assert.equal(result2, 7000); 15 | 16 | let result3 = multiMap("hi", 5, function(s) { 17 | return s + "!"; 18 | }); 19 | assert.equal(result3, 'hi!!!!!'); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/04-my-filter-test.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const spies = require("chai-spies"); 3 | const expect = chai.expect; 4 | chai.use(spies); 5 | 6 | const myFilter = require("../problems/04-my-filter.js"); 7 | 8 | describe("myFilter", function() { 9 | it("should mimic the built-in Array.filter", function() { 10 | let result1 = myFilter([5, 7, 4, 3, 8], function(n) { 11 | return n % 2 === 0; 12 | }); 13 | expect(result1).to.eql([ 4, 8 ]); 14 | 15 | let result2 = myFilter(["choose", "big", "words", "only"], function(s) { 16 | return s.length > 3; 17 | }); 18 | expect(result2).to.eql(['choose', 'words', 'only']); 19 | }); 20 | 21 | it("should not call the built-in Array.filter", function() { 22 | const filterSpy = chai.spy.on(Array.prototype, "filter"); 23 | myFilter([5, 7, 4, 3, 8], function(n) { 24 | return n % 2 === 0; 25 | }); 26 | expect(filterSpy).to.have.not.been.called(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/05-selective-map-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const selectiveMap = require("../problems/05-selective-map.js"); 3 | 4 | describe("selectiveMap", function() { 5 | it("should selectively call the second callback if the value returns true on the first callback", function() { 6 | function isEven(n) { 7 | return n % 2 === 0; 8 | } 9 | 10 | function isPositive(n) { 11 | return n > 0; 12 | } 13 | 14 | function square(n) { 15 | return n * n; 16 | } 17 | 18 | function flipSign(n) { 19 | return n * -1; 20 | } 21 | 22 | assert.deepEqual(selectiveMap([8, 5, 10, 4], isEven, square), [ 64, 5, 100, 16 ]) 23 | assert.deepEqual(selectiveMap([-10, 4, 7, 6, -2, -9], isEven, flipSign), [ 10, -4, 7, -6, 2, -9 ]) 24 | assert.deepEqual(selectiveMap([-10, 4, 7, 6, -2, -9], isPositive, square), [-10, 16, 49, 36, -2, -9]) 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/06-reject-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const reject = require("../problems/06-reject.js"); 3 | 4 | describe("reject", function() { 5 | it("should return a new array containing elements of the original array that result in false when given to the callback.", function() { 6 | let isEven = function(n) { 7 | return n % 2 === 0; 8 | }; 9 | assert.deepEqual(reject([7, 8, 5, 6, 12, 11], isEven), [ 7, 5, 11 ]); 10 | 11 | let hasA = function(s) { 12 | return s.toLowerCase().includes('a'); 13 | }; 14 | assert.deepEqual(reject(['breadth', 'GRAPH', 'depth', 'height'], hasA), [ 'depth', 'height' ]); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/07-my-some-test.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const spies = require("chai-spies"); 3 | const expect = chai.expect; 4 | chai.use(spies); 5 | 6 | const mySome = require("../problems/07-my-some.js"); 7 | 8 | describe("mySome", function() { 9 | it("should mimic the built-in Array.some", function() { 10 | let result1 = mySome([5, 1, 7, 9], function(ele, i) { 11 | return ele === i; 12 | }); 13 | expect(result1).to.be.true; 14 | 15 | let result2 = mySome([5, 3, 7, 9], function(ele, i) { 16 | return ele === i; 17 | }); 18 | expect(result2).to.be.false; 19 | 20 | let result3 = mySome(["soup", "noodles", "bike", "ship"], function(ele) { 21 | return ele.length === 4; 22 | }); 23 | expect(result3).to.be.true; 24 | }); 25 | 26 | it("should not call the built-in Array.some", function() { 27 | const someSpy = chai.spy.on(Array.prototype, "some"); 28 | mySome([5, 1, 7, 9], function(ele, i) { 29 | return ele === i; 30 | }); 31 | expect(someSpy).to.have.not.been.called(); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/08-count-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const count = require("../problems/08-count.js"); 3 | 4 | describe("count", function() { 5 | it("should return the number of elements of the array that return true when passed to the callback", function() { 6 | let result1 = count([18, 5, 32, 7, 100], function(n) { 7 | return n % 2 === 0; 8 | }); 9 | assert.equal(result1, 3); 10 | 11 | let result2 = count([17, 5, 31, 7, 100], function(n) { 12 | return n % 2 === 0; 13 | }); 14 | assert.equal(result2, 1); 15 | 16 | let result3 = count(["follow", "the", "yellow", "brick", "road"], function( 17 | str 18 | ) { 19 | return str.includes("o"); 20 | }); 21 | assert.equal(result3, 3); 22 | 23 | let result4 = count(["follow", "the", "yellow", "brick", "road"], function( 24 | str 25 | ) { 26 | return str.includes("x"); 27 | }); 28 | assert.equal(result4, 0); 29 | }); 30 | }); 31 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/09-chain-map-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const chainMap = require("../problems/09-chain-map.js"); 3 | 4 | describe("chainMap", function() { 5 | it("should return the final result of passing the value through all of the given callbacks", function() { 6 | let add5 = function(n) { 7 | return n + 5; 8 | }; 9 | 10 | let half = function(n) { 11 | return n / 2; 12 | }; 13 | 14 | let square = function(n) { 15 | return n * n; 16 | }; 17 | 18 | assert.equal(chainMap(25, add5), 30); 19 | assert.equal(chainMap(25, add5, half), 15); 20 | assert.equal(chainMap(25, add5, half, square), 225); 21 | assert.equal(chainMap(4, square, half), 8); 22 | assert.equal(chainMap(4, half, square), 4); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/10-my-every-test.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const spies = require("chai-spies"); 3 | const expect = chai.expect; 4 | chai.use(spies); 5 | 6 | const myEvery = require("../problems/10-my-every.js"); 7 | 8 | describe("myEvery", function() { 9 | it("should mimic the built-in Array.myEvery", function() { 10 | let isEven = function(num) { 11 | return num % 2 === 0; 12 | }; 13 | 14 | let hasO = function(string) { 15 | return string.includes("o"); 16 | }; 17 | 18 | expect(myEvery([4, 8, 6, 10], isEven)).to.be.true; 19 | expect(myEvery([4, 7, 6, 10], isEven)).to.be.false; 20 | expect(myEvery(["book", "door"], hasO)).to.be.true; 21 | expect(myEvery(["book", "door", "pen"], hasO)).to.be.false; 22 | }); 23 | 24 | it("should not call the built-in Array.every", function() { 25 | const everySpy = chai.spy.on(Array.prototype, "every"); 26 | myEvery([4, 8, 6, 10], function(num) { 27 | return num % 2 === 0; 28 | }); 29 | expect(everySpy).to.have.not.been.called(); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/11-and-select-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const andSelect = require("../problems/11-and-select.js"); 3 | 4 | describe("andSelect", function() { 5 | it("should return a new array containing elements of the original array that result in true when passed into both callbacks", function() { 6 | let isEven = function(n) { 7 | return n % 2 === 0; 8 | }; 9 | 10 | let isPositive = function(n) { 11 | return n > 0; 12 | }; 13 | 14 | const actual1 = andSelect([-3, 8, 7, 11, 6, 12, -4], isEven, isPositive); 15 | const expected1 = [8, 6, 12]; 16 | assert.deepEqual(actual1, expected1); 17 | 18 | let isUpperCase = function(s) { 19 | return s === s.toUpperCase(); 20 | }; 21 | 22 | let startsWithA = function(s) { 23 | return s[0].toUpperCase() === "A"; 24 | }; 25 | const actual2 = andSelect( 26 | ["ants", "APPLES", "ART", "BACON", "arm"], 27 | isUpperCase, 28 | startsWithA 29 | ); 30 | const expected2 = ["APPLES", "ART"]; 31 | assert.deepEqual(actual2, expected2); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/12-exactly-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const exactly = require("../problems/12-exactly.js"); 3 | 4 | describe("exactly", function() { 5 | it("should return a boolean indicating whether or not there are exactly `number` elements of the array that return true when passed into the callback", function() { 6 | let result1 = exactly([18, 5, 32, 7, 100], 3, function(n) { 7 | return n % 2 === 0; 8 | }); 9 | assert.equal(result1, true); 10 | 11 | let result2 = exactly([18, 5, 32, 7, 100], 2, function(n) { 12 | return n % 2 === 0; 13 | }); 14 | assert.equal(result2, false); 15 | 16 | let result3 = exactly( 17 | ["follow", "the", "yellow", "brick", "road"], 18 | 1, 19 | function(str) { 20 | return str.includes("x"); 21 | } 22 | ); 23 | assert.equal(result3, false); 24 | 25 | let result4 = exactly( 26 | ["follow", "the", "yellow", "brick", "road"], 27 | 0, 28 | function(str) { 29 | return str.includes("x"); 30 | } 31 | ); 32 | assert.equal(result4, true); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/13-min-value-callback-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const minValueCallback = require("../problems/13-min-value-callback.js"); 3 | 4 | describe("minValueCallback", function() { 5 | it("should return the smallest value in the array if a callback is not passed in", function() { 6 | assert.equal(minValueCallback([64, 25, 49, 9, 100]), 9); 7 | }); 8 | it("should return the smallest value in the array after passing through the callback if a callback is passed in", function() { 9 | assert.equal(minValueCallback([64, 25, 49, 9, 100], Math.sqrt), 3); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/14-map-mutator-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const mapMutator = require("../problems/14-map-mutator.js"); 3 | 4 | describe("mapMutator", function() { 5 | it("should pass each element and index into the callback and use the result to overwrite elements of the original array", function() { 6 | let arr1 = [4, 2, 6, 5]; 7 | mapMutator(arr1, function(el) { 8 | return el * 2; 9 | }); 10 | assert.deepEqual(arr1, [ 8, 4, 12, 10 ]); 11 | 12 | let arr2 = [8, 9, 10]; 13 | mapMutator(arr2, function(el, i) { 14 | return el * i; 15 | }); 16 | assert.deepEqual(arr2, [ 0, 9, 20 ]); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/15-sentence-mapper-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const sentenceMapper = require("../problems/15-sentence-mapper.js"); 3 | 4 | describe("sentenceMapper", function() { 5 | it("should return a new sentence where every word of the original sentence becomes the result of passing the word to the callback", function() { 6 | let result1 = sentenceMapper("what is the answer?", function(word) { 7 | return word.toUpperCase() + "!"; 8 | }); 9 | assert.equal(result1, "WHAT! IS! THE! ANSWER?!"); 10 | 11 | let removeVowels = function(word) { 12 | let newWord = ""; 13 | for (let i = 0; i < word.length; i++) { 14 | let char = word[i]; 15 | if (!"aeiou".includes(char)) { 16 | newWord += char; 17 | } 18 | } 19 | return newWord; 20 | }; 21 | 22 | let result2 = sentenceMapper("this is pretty cool right", removeVowels); 23 | assert.equal(result2, "ths s prtty cl rght"); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/16-suffix-cipher-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const suffixCipher = require("../problems/16-suffix-cipher.js"); 3 | 4 | describe("suffixCipher", function() { 5 | it("should return a new sentence where words of the original sentence are modified according to the callback that corresponds with the suffix that the word ends with", function() { 6 | let cipher1 = { 7 | ly: function(word) { 8 | return word.slice(0, -1) + "ee"; 9 | }, 10 | ize: function(word) { 11 | return word + "r"; 12 | } 13 | }; 14 | let actual1 = suffixCipher("quietly and gently visualize", cipher1); 15 | let expected1 = 'quietlee and gentlee visualizer'; 16 | assert.equal(actual1, expected1); 17 | 18 | let cipher2 = { 19 | tal: function(word) { 20 | return word.toUpperCase(); 21 | }, 22 | s: function(word) { 23 | return word + "th"; 24 | } 25 | }; 26 | let actual2 = suffixCipher("incremental progress is very instrumental", cipher2); 27 | let expected2 = 'INCREMENTAL progressth isth very INSTRUMENTAL'; 28 | assert.equal(actual2, expected2); 29 | }); 30 | }); 31 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/17-xor-select-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const xorSelect = require("../problems/17-xor-select.js"); 3 | 4 | describe("xorSelect", function() { 5 | it("should return a new array containing elements of the original array that result in true when passed in one of the callbacks, but not both", function() { 6 | let isEven = function(n) { 7 | return n % 2 === 0; 8 | }; 9 | 10 | let isPositive = function(n) { 11 | return n > 0; 12 | }; 13 | 14 | let result1 = xorSelect([-2, -1, 1, 2, 3, 4], isEven, isPositive); 15 | assert.deepEqual(result1, [-2, 1, 3]); 16 | 17 | let longString = function(s) { 18 | return s.length > 4; 19 | }; 20 | 21 | let startsA = function(s) { 22 | return s[0] === "a"; 23 | }; 24 | 25 | let result2 = xorSelect( 26 | ["art", "academy", "app", "cat", "buttery"], 27 | longString, 28 | startsA 29 | ); 30 | assert.deepEqual(result2, ["art", "app", "buttery"]); 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/18-one-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const one = require("../problems/18-one.js"); 3 | 4 | describe("one", function() { 5 | it("should return a boolean indicating whether or not exactly one element of the array results in true when passed into the callback", function() { 6 | let result1 = one(["x", "y", "z"], function(el) { 7 | return el === "a"; 8 | }); 9 | assert.equal(result1, false); 10 | 11 | let result2 = one(["x", "a", "y", "z"], function(el) { 12 | return el === "a"; 13 | }); 14 | assert.equal(result2, true); 15 | 16 | let result3 = one(["x", "a", "y", "a", "z"], function(el) { 17 | return el === "a"; 18 | }); 19 | assert.equal(result3, false); 20 | 21 | let result4 = one(["apple", "dog"], function(el) { 22 | return el.length > 3; 23 | }); 24 | assert.equal(result4, true); 25 | 26 | let result5 = one(["apple", "dog", "pear"], function(el) { 27 | return el.length > 3; 28 | }); 29 | assert.equal(result5, false); 30 | 31 | let result6 = one(["apple", "dog", "food", "cat"], function(el, idx) { 32 | return el.length === idx; 33 | }); 34 | assert.equal(result6, true); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/19-greater-callback-value-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const greaterCallbackValue = require("../problems/19-greater-callback-value.js"); 3 | 4 | describe("greaterCallbackValue", function() { 5 | it("should pass the value to both callbacks and return the greater of the results", function() { 6 | let doubler = function(n) { 7 | return 2 * n; 8 | }; 9 | 10 | let squarer = function(n) { 11 | return n * n; 12 | }; 13 | 14 | assert.equal(greaterCallbackValue(5, doubler, squarer), 25); 15 | assert.equal(greaterCallbackValue(1, doubler, squarer), 2); 16 | assert.equal(greaterCallbackValue(9, Math.sqrt, doubler), 18); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/20-none-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const none = require("../problems/20-none.js"); 3 | 4 | describe("none", function() { 5 | it("should return true if all elements of the array result to false when passed into the callback", function() { 6 | let result1 = none(['ruby', 'topaz', 'opal'], function(w) { 7 | return w.includes('e'); 8 | }); 9 | assert.equal(result1, true); 10 | 11 | let result2 = none([4, 5, 7, 1], function(n) { 12 | return n < 0; 13 | }); 14 | assert.equal(result2, true); 15 | }); 16 | it("should return false if only some or none elements of the array result to false when passed into the callback", function() { 17 | let result3 = none(['ruby', 'topaz', 'sapphire', 'opal'], function(w) { 18 | return w.includes('e'); 19 | }); 20 | assert.equal(result3, false); 21 | 22 | let result4 = none([4, -5, 7, -1], function(n) { 23 | return n < 0; 24 | }); 25 | assert.equal(result4, false); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/21-at-most-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const atMost = require("../problems/21-at-most.js"); 3 | 4 | describe("atMost", function() { 5 | it("should return a boolean indicating whether or not there are no more than `max` elements of the array that result in true when passed into the callback", function() { 6 | let isPositive = function(n) { 7 | return n > 0; 8 | }; 9 | let startsWithA = function(s) { 10 | return s[0].toUpperCase() === "A"; 11 | }; 12 | 13 | assert.equal(atMost([6, -2, 4, -1], 3, isPositive), true); 14 | assert.equal(atMost([6, -2, 4, 1], 3, isPositive), true); 15 | assert.equal(atMost([6, 2, 4, 1], 3, isPositive), false); 16 | assert.equal(atMost(["boat", "cat", "car"], 1, startsWithA), true); 17 | assert.equal( 18 | atMost(["boat", "cat", "car", "academy"], 1, startsWithA), 19 | true 20 | ); 21 | assert.equal( 22 | atMost(["boat", "arc", "cat", "car", "academy"], 1, startsWithA), 23 | false 24 | ); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/22-first-index-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const firstIndex = require("../problems/22-first-index.js"); 3 | 4 | describe("firstIndex", function() { 5 | it("should return the index of the first element of the array that results in true when passed into the callback", function() { 6 | let result1 = firstIndex([3, 7, 8, 10], function(n) { 7 | return n % 2 === 0; 8 | }); 9 | assert.equal(result1, 2); 10 | 11 | let result2 = firstIndex(["dog", "cat", "tree"], function(s) { 12 | return s.length === 3; 13 | }); 14 | assert.equal(result2, 0); 15 | }); 16 | it("should return -1 if no elements of the array result in true", function() { 17 | let result3 = firstIndex(["canine", "feline", "tree"], function(s) { 18 | return s.length === 3; 19 | }); 20 | assert.equal(result3, -1); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/23-alternating-map-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const alternatingMap = require("../problems/23-alternating-map.js"); 3 | 4 | describe("alternatingMap", function() { 5 | it("should return a new array containing the results of passing the values into the callbacks in an alternating fashion", function() { 6 | const triple = function(n) { 7 | return 3 * n; 8 | }; 9 | 10 | const half = function(n) { 11 | return n / 2; 12 | }; 13 | 14 | const actual1 = alternatingMap([7, 3, 2, 9, 8], triple, half); 15 | const expected1 = [21, 1.5, 6, 4.5, 24]; 16 | assert.deepEqual(actual1, expected1); 17 | 18 | const yell = function(s) { 19 | return s.toUpperCase() + "!"; 20 | }; 21 | 22 | const whisper = function(s) { 23 | return ".." + s.toLowerCase() + ".."; 24 | }; 25 | 26 | const actual2 = alternatingMap( 27 | ["hEy", "EVERYone", "whats", "uP??"], 28 | yell, 29 | whisper 30 | ); 31 | const expected2 = ["HEY!", "..everyone..", "WHATS!", "..up??.."]; 32 | assert.deepEqual(actual2, expected2); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /w2/solutions/callbacks/try-out-callbacks/test/24-my-simple-reduce-test.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const mySimpleReduce = require("../problems/24-my-simple-reduce.js"); 3 | 4 | describe("mySimpleReduce", function() { 5 | it("should mimic the behavior of the built in Array.reduce", function() { 6 | let result1 = mySimpleReduce([5, 3, 2, 4], function(sum, el) { 7 | return sum + el; 8 | }); 9 | assert.equal(result1, 14); 10 | 11 | let result2 = mySimpleReduce([4, 6, 2], function(product, el) { 12 | return product * el; 13 | }); 14 | assert.equal(result2, 48); 15 | 16 | let result3 = mySimpleReduce([4, 6, 2, 8, 3], function(max, el) { 17 | if (el > max) { 18 | return el; 19 | } else { 20 | return max; 21 | } 22 | }); 23 | assert.equal(result3, 8); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /w2/solutions/pojo-fruits/build_trigger.md: -------------------------------------------------------------------------------- 1 | This file is used to manually trigger the build process. It is here to provide 2 | a defined place to commit a trivial change. It may be ignored by students. 3 | 4 | To use, simply add the date and time below and commit to branch->staging->master 5 | as normal. 6 | 7 | 8/3/23 3:52pm ET 8 | 09/01/2023 2:30pm ET 9 | -------------------------------------------------------------------------------- /w2/solutions/pojo-fruits/ghapp.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "programs": { 3 | "BP": true, 4 | "FT": true, 5 | "PT": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /w2/solutions/pojo-fruits/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "data-manipulation-long-practice-solution", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha", 11 | "test-with-json": "mocha --reporter json" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "dependencies": { 17 | "chai": "^4.2.0", 18 | "chai-spies": "^1.0.0", 19 | "mocha": "^6.2.2" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/build_trigger.md: -------------------------------------------------------------------------------- 1 | This file is used to manually trigger the build process. It is here to provide 2 | a defined place to commit a trivial change. It may be ignored by students. 3 | 4 | To use, simply add the date and time below and commit to branch->staging->master 5 | as normal. 6 | 7 | 8/3/23 3:52pm ET 8 | 09/01/2023 2:30pm ET 9 | -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pojo-basics", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "directories": { 6 | "test": "test" 7 | }, 8 | "scripts": { 9 | "test": "mocha", 10 | "test-with-json": "mocha --reporter json" 11 | }, 12 | "keywords": [], 13 | "author": "", 14 | "license": "ISC", 15 | "dependencies": { 16 | "chai": "^4.3.7", 17 | "mocha": "^10.2.0" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/problems/01-keys-in-object.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function called `keysInObject(obj)` that takes in an object and returns 3 | an array of all the keys within that Object. 4 | 5 | Do this once using using a `for...in` loop and once using `Object.keys`. 6 | 7 | Examples: 8 | 9 | let animals = {dog: 'Wolfie', cat: 'Jet', bison: 'Bilbo'} 10 | let foods = {apple: 'tart', lemon: 'sour', mango: 'sweet'} 11 | keysInObject(animals); // => ["dog", "cat", "bison"] 12 | keysInObject(foods); // => ["apple", "lemon", "mango"] 13 | ***********************************************************************/ 14 | 15 | function keysInObject(obj) { 16 | //!!START 17 | return Object.keys(obj); 18 | //!!END 19 | } 20 | //!!START SILENT 21 | // solution 2 22 | // function keysInObject(obj) { 23 | // let array = []; 24 | // for (key in obj) { 25 | // array.push(key); 26 | // } 27 | // return array; 28 | // } 29 | //!!END 30 | 31 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 32 | module.exports = keysInObject; 33 | -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/problems/02-values-in-object.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function called `valuesInObject(obj)` that takes in an object and returns 3 | an array of all the values within that Object. 4 | 5 | 6 | Do this once using using a `for...in` loop and once using `Object.values`. 7 | 8 | 9 | Examples: 10 | 11 | let animals = {dog: "Wolfie", cat: "Jet", bison: "Bilbo"} 12 | let foods = {apple: "tart", lemon: "sour", mango: "sweet"} 13 | valuesInObject(animals); // => ["Wolfie", "Jet", "Bilbo"] 14 | valuesInObject(foods); // => ["tart", "sour", "sweet"] 15 | ***********************************************************************/ 16 | 17 | function valuesInObject(obj) { 18 | //!!START 19 | return Object.values(obj); 20 | //!!END 21 | } 22 | //!!START SILENT 23 | // solution 2 24 | // function valuesInObject(obj) { 25 | // let array = []; 26 | // for (key in obj) { 27 | // let value = obj[key]; 28 | // array.push(value); 29 | // } 30 | // return array; 31 | // } 32 | //!!END 33 | 34 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 35 | module.exports = valuesInObject; 36 | -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/problems/03-set-key-in-object.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function `setKeyInObject(obj, string, value)` that takes in three 3 | parameters. The first parameter is an object, the second parameter will be a 4 | string and the third parameter will be a value. Your job is to return the object 5 | adding the second parameter as a key using the third parameter as its value. 6 | 7 | Examples: 8 | 9 | let obj = {} 10 | setKeyInObject(obj, "apple", "yum"); // => {apple: "yum"} 11 | 12 | let obj1 = {str: "hello"} 13 | setKeyInObject(obj1, "num", 3); // => {str: "hello", num: 3} 14 | ***********************************************************************/ 15 | 16 | function setKeyInObject(obj, string, value) { 17 | //!!START 18 | let key = string; 19 | obj[key] = value; 20 | return obj; 21 | //!!END 22 | } 23 | 24 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 25 | module.exports = setKeyInObject; 26 | -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/problems/04-get-full-name.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function `getFullName(person)` that takes in an person object 3 | and returns a string containing their full name. 4 | 5 | 6 | Examples: 7 | let p1 = {firstName: 'John', lastName: 'Doe'}; 8 | getFullName(p1); // => 'John Doe' 9 | let p2 = {firstName: 'Charlie', lastName: 'Brown', age: 9}; 10 | getFullName(p2); // => 'Charlie Brown' 11 | ***********************************************************************/ 12 | 13 | function getFullName(person) { 14 | //!!START 15 | let name = person.firstName + " " + person.lastName; 16 | return name; 17 | //!!END 18 | } 19 | 20 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 21 | module.exports = getFullName; 22 | -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/problems/05-does-key-exist.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function `doesKeyExist(obj, key)` that takes in an object and a 3 | key and returns true if the key is inside the object and false if the 4 | key is not inside the object. 5 | 6 | Examples: 7 | 8 | let obj1 = {bootcamp: 'App Academy', course: 'Bootcamp Prep'} 9 | doesKeyExist(obj1, 'course'); // => true 10 | doesKeyExist(obj1, 'name'); // => false 11 | ***********************************************************************/ 12 | 13 | function doesKeyExist(obj, key) { 14 | //!!START 15 | return obj[key] !== undefined; 16 | //!!END 17 | } 18 | 19 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 20 | module.exports = doesKeyExist; 21 | -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/problems/07-value-pair.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function `valuePair(obj1, obj2, key)` that takes in two objects 3 | and a key (string). The function should return an array containing the 4 | corresponding values of the objects for the given key. 5 | 6 | Examples: 7 | let object1 = {name: 'One', location: 'NY', age: 3}; 8 | let object2 = {name: 'Two', location: 'SF'}; 9 | valuePair(object1, object2, 'location'); // => [ 'NY', 'SF' ] 10 | valuePair(object1, object2, 'name'); // => [ 'One', 'Two' ] 11 | ***********************************************************************/ 12 | 13 | function valuePair(obj1, obj2, key) { 14 | //!!START 15 | let val1 = obj1[key]; 16 | let val2 = obj2[key]; 17 | let arr = [val1, val2]; 18 | 19 | return arr; 20 | //!!END 21 | } 22 | 23 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 24 | module.exports = valuePair; 25 | -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/test/01-keys-in-object.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const keysInObject = require("../problems/01-keys-in-object.js"); 4 | 5 | describe("keysInObject()", function() { 6 | it("should return an array containing all object keys", function() { 7 | const animals = keysInObject({ dog: "Wolfie", cat: "Jet", bison: "Bilbo" }); 8 | const animalResult = ["dog", "cat", "bison"]; 9 | 10 | const foods = keysInObject({ 11 | apple: "tart", 12 | lemon: "sour", 13 | mango: "sweet" 14 | }); 15 | 16 | const foodResult = ["apple", "lemon", "mango"]; 17 | 18 | assert.deepEqual(animals, animalResult); 19 | assert.deepEqual(foods, foodResult); 20 | }); 21 | }); -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/test/02-values-in-object.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const valuesInObject = require("../problems/02-values-in-object.js"); 4 | 5 | describe("valuesInObject()", function() { 6 | it("should return an array containing all object values", function() { 7 | const animals = valuesInObject({ 8 | dog: "Wolfie", 9 | cat: "Jet", 10 | bison: "Bilbo" 11 | }); 12 | const animalResult = ["Wolfie", "Jet", "Bilbo"]; 13 | 14 | const foods = valuesInObject({ 15 | apple: "tart", 16 | lemon: "sour", 17 | mango: "sweet" 18 | }); 19 | const foodResult = ["tart", "sour", "sweet"]; 20 | 21 | assert.deepEqual(animals, animalResult); 22 | assert.deepEqual(foods, foodResult); 23 | }); 24 | }); -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/test/03-set-key-in-object.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | 4 | const setKeyInObject = require("../problems/03-set-key-in-object.js"); 5 | 6 | describe("setKeyInObject()", function() { 7 | it("should set a key-value pair into a given object", function() { 8 | let obj = {}; 9 | const test1 = setKeyInObject(obj, "apple", "yum"); 10 | const result1 = { apple: "yum" }; 11 | 12 | let obj1 = { str: "hello" }; 13 | const test2 = setKeyInObject(obj1, "num", 3); 14 | const result2 = { str: "hello", num: 3 }; 15 | 16 | assert.deepEqual(test1, result1); 17 | assert.deepEqual(test2, result2); 18 | }); 19 | }); -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/test/04-get-full-name.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const getFullName = require("../problems/04-get-full-name.js"); 4 | 5 | describe("getFullName()", function() { 6 | it("should return the full name values from within the object", function() { 7 | const p1 = { firstName: "John", lastName: "Doe" }; 8 | const test1 = getFullName(p1); 9 | const p2 = { firstName: "Charlie", lastName: "Brown", age: 9 }; 10 | const test2 = getFullName(p2); 11 | 12 | const result1 = "John Doe"; 13 | const result2 = "Charlie Brown"; 14 | 15 | assert.deepEqual(test1, result1); 16 | assert.deepEqual(test2, result2); 17 | }); 18 | }); -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/test/05-does-key-exist.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const doesKeyExist = require("../problems/05-does-key-exist.js"); 4 | 5 | describe("doesKeyExist()", function() { 6 | it("should return true if a key is within an object", function() { 7 | let obj1 = { bootcamp: "App Academy", course: "Bootcamp Prep" }; 8 | const test1 = doesKeyExist(obj1, "course"); 9 | const test2 = doesKeyExist(obj1, "name"); 10 | 11 | const result1 = true; 12 | const result2 = false; 13 | 14 | assert.deepEqual(test1, result1); 15 | assert.deepEqual(test2, result2); 16 | }); 17 | }); -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/test/06-key-in-object-array.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const keyInObjectArray = require("../problems/06-key-in-object-array.js"); 4 | 5 | describe("keyInObjectArray()", function() { 6 | it("should return true if a key is within any of the objects within the array", function() { 7 | let objArray = [ 8 | { name: "Rupert" }, 9 | { age: 42 }, 10 | { planet: "Earth", system: "Milky Way" } 11 | ]; 12 | const test1 = keyInObjectArray(objArray, "planet"); 13 | const test2 = keyInObjectArray(objArray, "age"); 14 | const test3 = keyInObjectArray(objArray, "food"); 15 | 16 | const result1 = true; 17 | const result2 = true; 18 | const result3 = false; 19 | 20 | assert.deepEqual(test1, result1); 21 | assert.deepEqual(test2, result2); 22 | assert.deepEqual(test3, result3); 23 | }); 24 | }); -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/test/07-value-pair.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const valuePair = require("../problems/07-value-pair.js"); 4 | 5 | describe("valuePair()", function() { 6 | it("should return an array of object keys and values", function() { 7 | const object1 = { name: "One", location: "NY", age: 3 }; 8 | const object2 = { name: "Two", location: "SF" }; 9 | 10 | const test1 = valuePair(object1, object2, "location"); 11 | const test2 = valuePair(object1, object2, "name"); 12 | 13 | const result1 = ["NY", "SF"]; 14 | const result2 = ["One", "Two"]; 15 | 16 | assert.deepEqual(test1, result1); 17 | assert.deepEqual(test2, result2); 18 | }); 19 | }); -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/test/08-apple-counter.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const appleCounter = require("../problems/08-apple-counter.js"); 4 | 5 | describe("appleCounter()", function() { 6 | it("should return a count of the number of keys that contain the word apple", function() { 7 | const obj = { banana: "yay!" }; 8 | const test1 = appleCounter(obj); // => 0 9 | 10 | const obj1 = { crabapple: "yum!" }; 11 | const test2 = appleCounter(obj1); // => 1 12 | 13 | const obj2 = { crabapple: "yum!", honeyapple: "super yum", banana: "yay" }; 14 | const test3 = appleCounter(obj2); // => 2 15 | 16 | const obj3 = { 17 | crabApple: "yum!", 18 | honeyApple: "super yum", 19 | banana: "yay", 20 | bigapple: "NYC" 21 | }; 22 | const test4 = appleCounter(obj3); // => 3 23 | 24 | const result1 = 0; 25 | const result2 = 1; 26 | const result3 = 2; 27 | const result4 = 3; 28 | 29 | assert.deepEqual(test1, result1); 30 | assert.deepEqual(test2, result2); 31 | assert.deepEqual(test3, result3); 32 | assert.deepEqual(test4, result4); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/test/09-array-converter.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const arrayConverter = require("../problems/09-array-converter.js"); 4 | 5 | describe("arrayConverter()", function() { 6 | it("should convert an array into an object with keys are the elements, and the values are the number of occurrences of each element", function() { 7 | const test1 = arrayConverter(["apple", "apple"]); 8 | const result1 = { apple: 2 }; 9 | 10 | const test2 = arrayConverter(["mango", "pineapple"]); 11 | const result2 = { mango: 1, pineapple: 1 }; 12 | 13 | const test3 = arrayConverter(["apple", "banana", "potato", "banana"]); 14 | const result3 = { apple: 1, banana: 2, potato: 1 }; 15 | 16 | assert.deepEqual(test1, result1); 17 | assert.deepEqual(test2, result2); 18 | assert.deepEqual(test3, result3); 19 | }); 20 | }); -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/test/10-string-converter.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const stringConverter = require("../problems/10-string-converter.js"); 4 | 5 | describe("stringConverter()", function() { 6 | it("should convert a string into an object with keys are the letters, and the values are the number of occurrences of each letter", function() { 7 | const apple = stringConverter("apple"); 8 | const appleResult = { a: 1, p: 2, l: 1, e: 1 }; 9 | 10 | const banana = stringConverter("banana"); 11 | const bananaResult = { b: 1, a: 3, n: 2 }; 12 | 13 | const raccoon = stringConverter("raccoon"); 14 | const raccoonResult = { r: 1, a: 1, c: 2, o: 2, n: 1 }; 15 | 16 | assert.deepEqual(apple, appleResult); 17 | assert.deepEqual(banana, bananaResult); 18 | assert.deepEqual(raccoon, raccoonResult); 19 | }); 20 | }); -------------------------------------------------------------------------------- /w2/solutions/pojo-practice/pojo-basics/test/11-count-scores.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const countScores = require("../problems/11-count-scores.js"); 4 | 5 | describe("countScores()", function() { 6 | it("should return an object of each person's total score", function() { 7 | const ppl = [ 8 | { name: "Anthony", score: 10 }, 9 | { name: "Fred", score: 10 }, 10 | { name: "Anthony", score: -8 }, 11 | { name: "Winnie", score: 12 } 12 | ]; 13 | const result1 = { Anthony: 2, Fred: 10, Winnie: 12 }; 14 | 15 | const peeps = [ 16 | { name: "Anthony", score: 2 }, 17 | { name: "Winnie", score: 2 }, 18 | { name: "Fred", score: 2 }, 19 | { name: "Winnie", score: 2 }, 20 | { name: "Fred", score: 2 }, 21 | { name: "Anthony", score: 2 }, 22 | { name: "Winnie", score: 2 } 23 | ]; 24 | const result2 = { Anthony: 4, Fred: 4, Winnie: 6 }; 25 | 26 | assert.deepEqual(countScores(ppl), result1); 27 | assert.deepEqual(countScores(peeps), result2); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/README.md: -------------------------------------------------------------------------------- 1 | ## Scope Problems 2 | 3 | It's time to get some practice using scope in the wild! This task includes a 4 | link to download a `zip` file with a number of problems. 5 | 6 | Complete the problems in the order specified. In addition to the prompts 7 | available at the top of each file, Mocha specs are provided to test your work. 8 | 9 | To get started, use the following commands: 10 | 11 | 1. `cd` into the project directory 12 | 2. `npm install` to install any dependencies 13 | 3. `npm test` to run the test cases 14 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/build_trigger.md: -------------------------------------------------------------------------------- 1 | This file is used to manually trigger the build process. It is here to provide 2 | a defined place to commit a trivial change. It may be ignored by students. 3 | 4 | To use, simply add the date and time below and commit to branch->staging->master 5 | as normal. 6 | 7 | 8/3/23 3:52pm ET 8 | 09/01/2023 2:30pm ET 9 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/naughty_list.md: -------------------------------------------------------------------------------- 1 | pt-split/ -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "solution", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha", 11 | "test-with-json": "mocha --reporter json" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "dependencies": { 17 | "chai": "^4.2.0", 18 | "chai-spies": "^1.0.0", 19 | "mocha": "^6.2.2" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/problems/00-arrow-addfive.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | We've just covered how to write functions using arrow function syntax. 3 | Let's give some old functions a new flair by rewriting them using fat arrow syntax. 4 | 5 | Write a function `addFive` that accepts a number and will return that number 6 | plus 5. Write this function on a single line, and utilize a fat arrow function's 7 | ability to implicitly return by leaving out your own return statement. 8 | 9 | 10 | Examples: 11 | let result1 = addFive(0); // returns 5 12 | let result2 = addFive(10); // returns 15 13 | let result3 = addFive(37); // returns 42 14 | 15 | 16 | ***********************************************************************/ 17 | 18 | //!!START 19 | let addFive = (num) => num + 5; 20 | //!!END 21 | 22 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 23 | try { 24 | module.exports = addFive; 25 | } catch (e) { 26 | return null; 27 | } 28 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/problems/01-arrow-full-name.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function using fat arrow syntax, `arrowGetFullName(person)` that takes in 3 | a person object and returns a string containing their full name. 4 | 5 | Assign the below function to a variable using the const keyword. Using the const 6 | keyword will allow any value assigned to that variable protection from being 7 | reassigned within that scope. 8 | 9 | Examples: 10 | let p1 = {firstName: 'John', lastName: 'Doe'}; 11 | arrowGetFullName(p1); // => 'John Doe' 12 | let p2 = {firstName: 'Charlie', lastName: 'Brown', age: 9}; 13 | arrowGetFullName(p2); // => 'Charlie Brown' 14 | 15 | ***********************************************************************/ 16 | 17 | //!!START 18 | const arrowGetFullName = (person) => person.firstName + " " + person.lastName; 19 | //!!END 20 | 21 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 22 | try { 23 | module.exports = arrowGetFullName; 24 | } catch (e) { 25 | return null; 26 | } 27 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/problems/02-arrow-my-map.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function using fat arrow syntax named `arrowMyMap` that accepts an array 3 | and a callback as arguments. The function will return an array of new elements 4 | obtained by calling the callback on each element of the array, passing in the 5 | element. Assign the below function to a variable using the const keyword. 6 | 7 | Do not use the built in Array.map - use Array.forEach for iteration. 8 | 9 | 10 | Examples: 11 | let result1 = arrowMyMap([100, 25, 81, 64], Math.sqrt); 12 | console.log(result1); // [ 10, 5, 9, 8 ] 13 | 14 | const yell = el => el.toUpperCase() + '!' 15 | 16 | let result2 = arrowMyMap(['run', 'Forrest'], yell); 17 | console.log(result2); // [ 'RUN!', 'FORREST!' ] 18 | 19 | ***********************************************************************/ 20 | 21 | const arrowMyMap = (array, cb) => { 22 | //!!START 23 | let mapped = []; 24 | 25 | array.forEach((el) => mapped.push(cb(el))); 26 | return mapped; 27 | //!!END 28 | }; 29 | 30 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 31 | try { 32 | module.exports = arrowMyMap; 33 | } catch (e) { 34 | return null; 35 | } 36 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/problems/03-arrow-rest-sum.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function named `arrowRestSum` that accepts all incoming parameters 3 | and sums them. Assign the below function to a variable using the const keyword. 4 | 5 | **Hint**: Use rest parameter syntax! 6 | 7 | Examples: 8 | arrowRestSum(3,5,6); // => 14 9 | arrowRestSum(1, 2, 3, 4, 5, 6, 7, 8, 9); // => 45 10 | arrowRestSum(0); // => 0 11 | ***********************************************************************/ 12 | 13 | const arrowRestSum = (...otherNums) => { 14 | //!!START 15 | let sum = otherNums.reduce((acc, el) => (acc += el)); 16 | return sum; 17 | //!!END 18 | }; 19 | 20 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 21 | try { 22 | module.exports = arrowRestSum; 23 | } catch (e) { 24 | return null; 25 | } 26 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/problems/04-arrow-average-value.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function using fat arrow syntax, `arrowAvgValue(array)` that takes in an 3 | array of numbers and returns the average number. Assign the below function to a 4 | variable using the const keyword. 5 | 6 | Examples: 7 | 8 | arrowAvgValue([10, 20]); // => 15 9 | arrowAvgValue([2, 3, 7]); // => 4 10 | arrowAvgValue([100, 60, 64]); // => 74.66666666666667 11 | ***********************************************************************/ 12 | 13 | const arrowAvgValue = array => { 14 | //!!START 15 | let sum = array.reduce((el, sum = 0) => (sum += el)); 16 | 17 | let avg = sum / array.length; 18 | return avg; 19 | //!!END 20 | }; 21 | 22 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 23 | try { 24 | module.exports = arrowAvgValue; 25 | } catch (e) { 26 | return null; 27 | } 28 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/problems/05-arrow-mirror-array.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function `mirrorArray(array)` that takes in an array as an 3 | argument and returns a new array "mirrored" as shown in the examples: 4 | 5 | Examples: 6 | 7 | mirrorArray([1,2,3]); // => [ 1, 2, 3, 3, 2, 1 ] 8 | mirrorArray(['a', 'b', 'c', 'd']); // => [ 'a', 'b', 'c', 'd', 'd', 'c', 'b', 'a' ] 9 | ***********************************************************************/ 10 | 11 | const mirrorArray = (array) => { 12 | //!!START 13 | let newArray = []; 14 | 15 | for (let i = 0; i < array.length; i += 1) { 16 | let el = array[i]; 17 | newArray.push(el); 18 | } 19 | 20 | for (let i = array.length - 1; i >= 0; i -= 1) { 21 | let el = array[i]; 22 | newArray.push(el); 23 | } 24 | 25 | return newArray; 26 | //!!END 27 | }; 28 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 29 | try { 30 | module.exports = mirrorArray; 31 | } catch (e) { 32 | return null; 33 | } 34 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/problems/07-set-time-out.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function named `funcTimer(time, func)` that will allow you to hand 3 | in a function and a number representing milliseconds. The `funcTimer` should use 4 | the global.setTimeout function to invoke the passed in function in `time` amount 5 | of seconds. 6 | 7 | There are no specs for this problem - try it in the console yourself to 8 | test your answer! 9 | 10 | Examples: 11 | 12 | function partyFunc () { 13 | console.log("Party time!") 14 | } 15 | 16 | funcTimer(5000, partyFunc); // in 5 seconds prints: "Party time!" 17 | 18 | 19 | ***********************************************************************/ 20 | 21 | function funcTimer(time, func) { 22 | //!!START 23 | setTimeout(func, time); 24 | //!!END 25 | } 26 | 27 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 28 | 29 | try { 30 | module.exports = funcTimer; 31 | } catch (e) { 32 | return null; 33 | } -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/problems/08-hidden-counter.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function named `hiddenCounter()`. This function will do two things - first 3 | it will define a count variable, then it will return a function. 4 | When invoked the function returned by hiddenCounter will increment the counter by 1. 5 | 6 | Look below to see how this function is invoked: 7 | 8 | let hidden1 = hiddenCounter(); //returns a function 9 | hidden1(); // returns 1 10 | hidden1(); // returns 2 11 | 12 | let hidden2 = hiddenCounter(); // returns a function 13 | hidden2(); // returns 1 14 | 15 | 16 | ***********************************************************************/ 17 | 18 | function hiddenCounter() { 19 | //!!START 20 | let count = 0; 21 | return () => (count += 1); 22 | //!!END 23 | } 24 | 25 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 26 | try { 27 | module.exports = hiddenCounter; 28 | } catch (e) { 29 | return null; 30 | } 31 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/problems/13-dynamic-divide.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function named `dynamicDivide(divisor)`. The dynamicDivide function will 3 | return a new function that when invoked will divide the argument number by the 4 | divisor. 5 | 6 | 7 | Look below to see how this function is invoked: 8 | 9 | const halfer = dynamicDivide(2); // returns a function 10 | halfer(20); // returns 10 11 | 12 | const divideByThree = dynamicDivide(3); 13 | divideByThree(30); // returns 10 14 | 15 | const divideByFive = dynamicDivide(5); 16 | divideByFive(50); // returns 10 17 | 18 | 19 | ***********************************************************************/ 20 | 21 | function dynamicDivide(divisor) { 22 | //!!START 23 | return function (dividend) { 24 | return dividend / divisor; 25 | }; 26 | //!!END 27 | } 28 | 29 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 30 | try { 31 | module.exports = dynamicDivide; 32 | } catch (e) { 33 | return null; 34 | } 35 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/problems/15-closure-dynamic-multi.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Let's practice writing closures by creating a method called `dynamicMultiply(num)`. 3 | The dynamicMultiply function will return a new function that will allow us to 4 | create new separate custom multiply functions. 5 | 6 | 7 | Look below to see how this function is invoked: 8 | 9 | const doubler = dynamicMultiply(2); // returns a functions 10 | doubler(5); // returns 10 11 | 12 | const tripler = dynamicMultiply(3); 13 | tripler(5); // returns 15 14 | 15 | const multiplyByFive = dynamicMultiply(5); 16 | multiplyByFive(5); // returns 25 17 | 18 | 19 | ***********************************************************************/ 20 | 21 | function dynamicMultiply(num) { 22 | //!!START 23 | let multiplier = num; 24 | 25 | return function(factor) { 26 | return multiplier * factor; 27 | }; 28 | //!!END 29 | } 30 | 31 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 32 | try { 33 | module.exports = dynamicMultiply; 34 | } catch (e) { 35 | return null; 36 | } 37 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/problems/16-coupon.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function named: coupon(discount). The coupon function will intake a 3 | number to apply as a discount, and will return a function that accepts an array 4 | of prices. Every call to the function returned by coupon will return the array 5 | of prices with the discount applied. 6 | 7 | Example 1: 8 | let tenPercent = coupon(0.1); 9 | console.log(tenPercent([10, 20, 30])); // [ 9, 18, 27 ] 10 | 11 | Example 2: 12 | let twentyPercent = coupon(0.2); 13 | console.log(twentyPercent([10, 20, 30])); // [ 8, 16, 24 ] 14 | 15 | 16 | ***********************************************************************/ 17 | function coupon(discount) { 18 | //!!START 19 | return (prices) => { 20 | return prices.map((price) => (price -= price * discount)); 21 | }; 22 | //!!END 23 | } 24 | 25 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 26 | try { 27 | module.exports = coupon; 28 | } catch (e) { 29 | return null; 30 | } 31 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/problems/17-arrow-reverse.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function reverseStr(str) that accepts a string and returns that string 3 | reversed. 4 | 5 | Write this function using a fat arrow function! 6 | 7 | Examples: 8 | let result1 = reverseStr("hello"); // returns "olleh" 9 | let result2 = reverseStr("garden"); // returns "nedrag" 10 | let result3 = reverseStr("potato"); // returns "otatop" 11 | 12 | 13 | ***********************************************************************/ 14 | 15 | //!!START 16 | let reverseStr = (str) => str.split("").reverse().join(""); 17 | //!!END 18 | 19 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 20 | try { 21 | module.exports = reverseStr; 22 | } catch (e) { 23 | return null; 24 | } 25 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/pt-split/part-1.md: -------------------------------------------------------------------------------- 1 | # Scope Project - Part 1 2 | 3 | In this project, you will be using your knowledge of scope to solve programming 4 | problems. 5 | 6 | In this part, you will be tackling the first 6 problems: 7 | 8 | - `00-arrow-addfive` 9 | - `01-arrow-full-name` 10 | - `02-arrow-my-map` 11 | - `03-arrow-rest-sum` 12 | - `04-arrow-average-value` 13 | - `05-arrow-mirror-array` 14 | 15 | You've probably seen some of these problems before. This time, try writing them 16 | with arrow function notation. Try to take advantage of the properties of 17 | arrow functions to solve these problems if possible. 18 | 19 | In addition to the prompts available at the top of each file, Mocha specs are 20 | provided to test your work. 21 | 22 | To get started, use the following commands: 23 | 24 | ```shell 25 | cd 26 | npm install 27 | npm test 28 | ``` 29 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/pt-split/part-2.md: -------------------------------------------------------------------------------- 1 | # Scope Project - Part 2 2 | 3 | In this project, you will be using your knowledge of scope to solve programming 4 | problems. 5 | 6 | In this part, you will be tackling the next 6 problems: 7 | 8 | - `06-closure-sandwiches` 9 | - `07-set-time-out` 10 | - `08-hidden-counter` 11 | - `09-interrupter` 12 | - `10-count-down` 13 | - `11-lazy-adder` 14 | 15 | Make sure to write your solutions using arrow function notation. Try to take 16 | advantage of the properties of arrow functions and/or closures to solve these 17 | problems if possible. 18 | 19 | Don't forget to run the Mocha to test your solutions. 20 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/pt-split/part-3.md: -------------------------------------------------------------------------------- 1 | # Scope Project - Part 3 2 | 3 | In this project, you will be using your knowledge of scope to solve programming 4 | problems. 5 | 6 | In this part, you will be tackling the next 5 problems: 7 | 8 | - `12-volume` 9 | - `13-dynamic-divide` 10 | - `14-smoothie-machine` 11 | - `15-closure-dynamic-multi` 12 | - `16-coupon` 13 | 14 | Make sure to write your solutions using arrow function notation. Try to take 15 | advantage of the properties of arrow functions and/or closures to solve these 16 | problems if possible. 17 | 18 | Don't forget to run the Mocha to test your solutions. 19 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/pt-split/part-4.md: -------------------------------------------------------------------------------- 1 | # Scope Project - Part 4 2 | 3 | In this project, you will be using your knowledge of scope to solve programming 4 | problems. 5 | 6 | In this part, you will be tackling the last 4 problems: 7 | 8 | - `17-arrow-reverse` 9 | - `18-planned-intersection` 10 | - `19-coin-collector` 11 | - `20-curried-sum` 12 | 13 | Make sure to write your solutions using arrow function notation. Try to take 14 | advantage of the properties of arrow functions and/or closures to solve these 15 | problems if possible. 16 | 17 | Don't forget to run the Mocha to test your solutions. 18 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/00-arrow-addfive-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const chai = require("chai"); 3 | const expect = chai.expect; 4 | const spies = require("chai-spies"); 5 | chai.use(spies); 6 | 7 | const addFive = require("../problems/00-arrow-addfive.js"); 8 | 9 | describe("addFive()", function () { 10 | it("should add 5 to any passed in argument", function () { 11 | const test1 = addFive(0); 12 | const result1 = 5; 13 | 14 | const test2 = addFive(10); 15 | const result2 = 15; 16 | 17 | const test3 = addFive(37); 18 | const result3 = 42; 19 | 20 | assert.deepEqual(test1, result1); 21 | assert.deepEqual(test2, result2); 22 | assert.deepEqual(test3, result3); 23 | }); 24 | 25 | it("should be an arrow function", function () { 26 | expect(typeof addFive.prototype).to.equal("undefined"); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/01-arrow-full-name-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const chai = require("chai"); 3 | const expect = chai.expect; 4 | const spies = require("chai-spies"); 5 | chai.use(spies); 6 | 7 | const arrowGetFullName = require("../problems/01-arrow-full-name.js"); 8 | 9 | describe("arrowGetFullName()", function () { 10 | it("should return the full name values from within the object", function () { 11 | const p1 = { firstName: "John", lastName: "Doe" }; 12 | const test1 = arrowGetFullName(p1); 13 | const p2 = { firstName: "Charlie", lastName: "Brown", age: 9 }; 14 | const test2 = arrowGetFullName(p2); 15 | 16 | const result1 = "John Doe"; 17 | const result2 = "Charlie Brown"; 18 | 19 | assert.deepEqual(test1, result1); 20 | assert.deepEqual(test2, result2); 21 | }); 22 | 23 | it("should be an arrow function", function () { 24 | expect(typeof arrowGetFullName.prototype).to.equal("undefined"); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/02-arrow-my-map-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const chai = require("chai"); 3 | const expect = chai.expect; 4 | const spies = require("chai-spies"); 5 | chai.use(spies); 6 | 7 | const arrowMyMap = require("../problems/02-arrow-my-map.js"); 8 | 9 | describe("arrowMyMap()", function () { 10 | it("should function like the built in Array.map", function () { 11 | let result1 = arrowMyMap([100, 25, 81, 64], Math.sqrt); 12 | expect(result1).to.eql([10, 5, 9, 8]); 13 | 14 | let result2 = arrowMyMap(["run", "Forrest"], function (el) { 15 | return el.toUpperCase() + "!"; 16 | }); 17 | expect(result2).to.eql(["RUN!", "FORREST!"]); 18 | }); 19 | 20 | it("should be an arrow function", function () { 21 | expect(typeof arrowMyMap.prototype).to.equal("undefined"); 22 | }); 23 | 24 | it("should not call the built in Array.map", function () { 25 | const mapSpy = chai.spy.on(Array.prototype, "map"); 26 | arrowMyMap([100, 25, 81, 64], Math.sqrt); 27 | expect(mapSpy).to.not.have.been.called(); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/03-arrow-rest-sum-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const chai = require("chai"); 3 | const expect = chai.expect; 4 | const spies = require("chai-spies"); 5 | chai.use(spies); 6 | 7 | const arrowRestSum = require("../problems/03-arrow-rest-sum.js"); 8 | 9 | describe("arrowRestSum()", function () { 10 | it("should add any number of incoming arguments", function () { 11 | const test1 = arrowRestSum(3, 5, 6); 12 | const result1 = 14; 13 | 14 | const test2 = arrowRestSum(1, 2, 3, 4, 5, 6, 7, 8, 9); 15 | const result2 = 45; 16 | 17 | const test3 = arrowRestSum(0, 0); 18 | const result3 = 0; 19 | 20 | assert.deepEqual(test1, result1); 21 | assert.deepEqual(test2, result2); 22 | assert.deepEqual(test3, result3); 23 | }); 24 | 25 | it("should be an arrow function", function () { 26 | expect(typeof arrowRestSum.prototype).to.equal("undefined"); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/04-arrow-average-value-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const chai = require("chai"); 3 | const expect = chai.expect; 4 | const spies = require("chai-spies"); 5 | chai.use(spies); 6 | 7 | const arrowAvgValue = require("../problems/04-arrow-average-value.js"); 8 | 9 | describe("arrowAvgValue()", function () { 10 | it("should return the average of an array of numbers", function () { 11 | assert.equal(arrowAvgValue([10, 20]), 15); 12 | assert.equal(arrowAvgValue([2, 3, 7]), 4); 13 | assert.equal(arrowAvgValue([100, 60, 64]), 74.66666666666667); 14 | }); 15 | 16 | it("should be an arrow function", function () { 17 | expect(typeof arrowAvgValue.prototype).to.equal("undefined"); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/05-arrow-mirror-array-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const chai = require("chai"); 3 | const expect = chai.expect; 4 | const spies = require("chai-spies"); 5 | chai.use(spies); 6 | 7 | const mirrorArray = require("../problems/05-arrow-mirror-array.js"); 8 | 9 | describe("mirrorArray()", function () { 10 | it("should return a single array where the first half is the original array and the second half is a mirror of the first half", function () { 11 | assert.deepEqual(mirrorArray([1, 2, 3]), [1, 2, 3, 3, 2, 1]); 12 | assert.deepEqual(mirrorArray(["a", "b", "c", "d"]), [ 13 | "a", 14 | "b", 15 | "c", 16 | "d", 17 | "d", 18 | "c", 19 | "b", 20 | "a", 21 | ]); 22 | }); 23 | 24 | it("should be an arrow function", function () { 25 | expect(typeof mirrorArray.prototype).to.equal("undefined"); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/06-closure-sandwiches-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const chai = require("chai"); 3 | const expect = chai.expect; 4 | const spies = require("chai-spies"); 5 | chai.use(spies); 6 | 7 | const sandwichMaker = require("../problems/06-closure-sandwiches.js"); 8 | 9 | describe("sandwichMaker()", function () { 10 | it("should return a function that accepts new arguments for the order", function () { 11 | let sandwich = sandwichMaker(); 12 | let result1 = "One sandwich with tomato and spinach"; 13 | let result2 = "One sandwich with tomato and spinach and jelly"; 14 | let result3 = "One sandwich with tomato and spinach and jelly and bread"; 15 | 16 | assert.equal(sandwich("spinach"), result1); 17 | assert.equal(sandwich("jelly"), result2); 18 | assert.equal(sandwich("bread"), result3); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/07-set-time-out-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const chai = require("chai"); 3 | const expect = chai.expect; 4 | const spies = require("chai-spies"); 5 | chai.use(spies); 6 | 7 | const funcTimer = require("../problems/07-set-time-out"); 8 | 9 | describe("funcTimer()", function () { 10 | it("should invoke the callback function after a specified time", function (done) { 11 | let startTime = new Date(); 12 | let msecs = 500; 13 | 14 | this.timeout(msecs + 500); 15 | 16 | funcTimer(msecs, function() { 17 | let endTime = new Date(); 18 | let diff = endTime - startTime; 19 | assert.equal(diff >= msecs - 10, true); 20 | assert.equal(diff <= msecs + 10, true); 21 | done(); 22 | }); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/08-hidden-counter-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const hiddenCounter = require("../problems/08-hidden-counter.js"); 3 | 4 | describe("hiddenCounter()", function () { 5 | it("should return a function that will increment the counter when invoked", function () { 6 | let hidden1 = hiddenCounter(); 7 | hidden1(); 8 | let testResult1 = hidden1(); 9 | 10 | let hidden2 = hiddenCounter(); 11 | let testResult2 = hidden2(); 12 | assert.equal(testResult1, 2); 13 | assert.equal(testResult2, 1); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/09-interrupter-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const interrupter = require("../problems/09-interrupter.js"); 3 | 4 | describe("interrupter()", function () { 5 | it("should return a function that accepts new arguments and interjects the original passed in word", function () { 6 | let rudePerson = interrupter("what"); 7 | let rudePerson2 = interrupter("yo"); 8 | let result1 = "how what are what you"; 9 | let result2 = "I what like what pie"; 10 | let result3 = "I yo love yo dogs"; 11 | 12 | assert.equal(rudePerson("how are you"), result1); 13 | assert.equal(rudePerson("I like pie"), result2); 14 | assert.equal(rudePerson2("I love dogs"), result3); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/10-count-down-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const countDownTimer = require("../problems/10-count-down.js"); 4 | 5 | describe("countDownTimer()", function () { 6 | it("should return a function the specified number of times until it returns 'Happy New Year'", function () { 7 | let threeDays = countDownTimer(3); 8 | threeDays(); 9 | threeDays(); 10 | 11 | let twoDays = countDownTimer(2); 12 | twoDays(); 13 | 14 | let oneDay = countDownTimer(1); 15 | 16 | assert.equal(threeDays(), "Happy New Year!"); 17 | assert.equal(twoDays(), "Happy New Year!"); 18 | assert.equal(oneDay(), "Happy New Year!"); 19 | assert.equal(countDownTimer(0), "Happy New Year!"); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/11-lazy-adder-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const lazyAdder = require("../problems/11-lazy-adder.js"); 3 | 4 | describe("lazyAdder()", function () { 5 | it(`should return and add input numbers through numerous function calls`, function () { 6 | let firstAdd = lazyAdder(1); 7 | let secondAdd = firstAdd(2); 8 | let sum = secondAdd(3); 9 | 10 | let func1 = lazyAdder(10); 11 | let func2 = func1(20); 12 | let total = func2(3); 13 | 14 | assert.equal(sum, 6); 15 | assert.equal(total, 33); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/12-volume-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const chai = require("chai"); 3 | const expect = chai.expect; 4 | const spies = require("chai-spies"); 5 | chai.use(spies); 6 | 7 | const recVolume = require("../problems/12-volume.js"); 8 | 9 | describe("recVolume()", function () { 10 | it("should return a function that can be invoked twice to find the volume of a rectangle", function () { 11 | let table1 = recVolume(5); 12 | table1(4); 13 | expect(table1(3)).to.eql(60); 14 | 15 | let table2 = recVolume(3); 16 | table2(2); 17 | expect(table2(1)).to.eql(6); 18 | }); 19 | 20 | it("should continue to return the same volume once it has 3 measurements", function () { 21 | let table1 = recVolume(5); 22 | table1(4); 23 | expect(table1(3)).to.eql(60); 24 | expect(table1(145)).to.eql(60); 25 | expect(table1(2)).to.eql(60); 26 | 27 | let table2 = recVolume(3); 28 | table2(2); 29 | expect(table2(1)).to.eql(6); 30 | expect(table2(76)).to.eql(6); 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/13-dynamic-divide-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const dynamicDivide = require("../problems/13-dynamic-divide.js"); 3 | 4 | describe("dynamicDivide()", function () { 5 | it("should return a function that accepts a number", function () { 6 | const halfer = dynamicDivide(2); 7 | 8 | assert.doesNotThrow(() => halfer(5), TypeError); 9 | }); 10 | 11 | it("should return a new multiply function for each initial argument", function () { 12 | const halfer = dynamicDivide(2); 13 | 14 | const divideByThree = dynamicDivide(3); 15 | 16 | const divideByFive = dynamicDivide(5); 17 | 18 | assert.equal(halfer(20), 10); 19 | assert.equal(divideByThree(30), 10); 20 | assert.equal(divideByFive(50), 10); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/15-closure-dynamic-multi-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const dynamicMultiply = require("../problems/15-closure-dynamic-multi.js"); 3 | 4 | describe("dynamicMultiply()", function () { 5 | it("should return a function that accepts a number", function () { 6 | const doubler = dynamicMultiply(2); 7 | 8 | assert.equal(doubler(5), 10); 9 | }); 10 | 11 | it("should return a new multiply function for each initial argument", function () { 12 | const tripler = dynamicMultiply(3); 13 | const multiplyByFive = dynamicMultiply(5); 14 | 15 | assert.equal(tripler(5), 15); 16 | assert.equal(multiplyByFive(5), 25); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/16-coupon-spec.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const expect = chai.expect; 3 | 4 | const coupon = require("../problems/16-coupon.js"); 5 | 6 | describe("coupon()", function () { 7 | it("should return a function that accepts an array of prices to apply the discount to", function () { 8 | let tenPercent = coupon(0.1); 9 | let twentyPercent = coupon(0.2); 10 | 11 | expect(tenPercent([10, 20, 30])).to.eql([9, 18, 27]); 12 | expect(tenPercent).to.be.a("function"); 13 | expect(twentyPercent([10, 20, 30])).to.eql([8, 16, 24]); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/17-arrow-reverse-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const chai = require("chai"); 3 | const expect = chai.expect; 4 | const spies = require("chai-spies"); 5 | chai.use(spies); 6 | 7 | const reverseStr = require("../problems/17-arrow-reverse.js"); 8 | describe("reverseStr()", function () { 9 | it("should reverse the passed in string argument", function () { 10 | const test = reverseStr("hello"); 11 | const result = "olleh"; 12 | 13 | const test2 = reverseStr("garden"); 14 | const result2 = "nedrag"; 15 | 16 | const test3 = reverseStr("potato"); 17 | const result3 = "otatop"; 18 | 19 | assert.deepEqual(test, result); 20 | assert.deepEqual(test2, result2); 21 | assert.deepEqual(test3, result3); 22 | }); 23 | 24 | it("should be an arrow function", function () { 25 | expect(typeof reverseStr.prototype).to.equal("undefined"); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/18-planned-intersection-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const chai = require("chai"); 3 | const expect = chai.expect; 4 | const spies = require("chai-spies"); 5 | chai.use(spies); 6 | 7 | const plannedIntersect = require("../problems/18-planned-intersection.js"); 8 | 9 | describe("plannedIntersect()", function () { 10 | it("when invoked it should return a function", function () { 11 | let abc = plannedIntersect(["a", "b", "c"]); 12 | 13 | expect(abc).to.be.a("function"); 14 | }); 15 | 16 | it("when the function returned by plannedIntersect is invoked with an array it should return a list of common elements", function () { 17 | let abc = plannedIntersect(["a", "b", "c"]); 18 | let fame = plannedIntersect(["f", "a", "m", "e"]); 19 | 20 | expect(abc(["b", "d", "c"]).sort()).to.eql(["b", "c"]); 21 | expect(fame(["a", "f", "z", "b"]).sort()).to.eql(["a", "f"]); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/19-coin-collector-spec.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const expect = chai.expect; 3 | const spies = require("chai-spies"); 4 | chai.use(spies); 5 | 6 | const coinCollector = require("../problems/19-coin-collector.js"); 7 | 8 | describe("coinCollector()", function () { 9 | it("should return a function numCoins number of times before returning an array of all collected coins", function () { 10 | let oneCoin = coinCollector(1); 11 | 12 | let twoCoins = coinCollector(2); 13 | twoCoins(25); 14 | 15 | let threeCoins = coinCollector(3); 16 | threeCoins(25); 17 | threeCoins(5); 18 | 19 | expect(oneCoin).to.be.a("function"); 20 | expect(oneCoin(10)).to.eql([10]); 21 | expect(twoCoins).to.be.a("function"); 22 | expect(twoCoins(10)).to.eql([25, 10]); 23 | expect(threeCoins).to.be.a("function"); 24 | expect(threeCoins(10)).to.eql([25, 5, 10]); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /w2/solutions/scope-problems-without-context/test/20-curried-sum-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const curriedSum = require("../problems/20-curried-sum.js"); 4 | 5 | describe("curriedSum()", function () { 6 | it("should sum numbers using currying", function () { 7 | const sum = curriedSum(4); 8 | sum(5); 9 | sum(20); 10 | sum(30); 11 | let testResult = sum(20); 12 | assert.equal(testResult, 75); 13 | }); 14 | it("should allow the calculator to add multiple numbers using currying", function () { 15 | const testResult = curriedSum(3)(2)(1)(7); 16 | assert.equal(testResult, 10); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /w3/README.md: -------------------------------------------------------------------------------- 1 | # Week 3 Additional Resources 2 | 3 | ## Learning Objectives 4 | 5 | * Recursion 6 | * Given a recursive function, identify what is the base case and the recursive case. 7 | * Identify and use default parameters for functions. 8 | * Define what a "stack overflow" means in JavaScript's call stack. 9 | * Identify what causes the error `RangeError: Maximum call stack`. 10 | * Map out the recursive call stack when running a test case through a recursion function. 11 | * Solve problems using recursion. 12 | * Given a buggy recursive function, debug the function. 13 | * Asynchronicity 14 | * Identify JavaScript as a language that utilizes an event loop model. 15 | * Identify JavaScript as a single threaded language. 16 | * Describe the difference between asynchronous and synchronous code. 17 | * Execute the asynchronous function `setTimeout` with a callback. 18 | * Use `setInterval` to have a function execute 10 times with a 1 second period. After the 10th cycle, clear the interval. 19 | * Write a program that accepts user input using Node’s readline module (only for working on Guessing Game Project). -------------------------------------------------------------------------------- /w3/d1/lecture.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function foo(word) { 4 | debugger; 5 | console.log(word); 6 | bar("barber"); 7 | } 8 | 9 | function bar(word) { 10 | debugger; 11 | console.log(word); 12 | baz("bazaar"); 13 | } 14 | 15 | function baz(word) { 16 | console.log(word); 17 | // debugger; // trigger debugger 18 | } 19 | 20 | // foo("food"); 21 | 22 | function test() { 23 | let name = "brandon"; 24 | debugger; 25 | 26 | if (false) { 27 | name = "false"; 28 | debugger; 29 | } 30 | if (true) { 31 | name = "krandon"; 32 | debugger; 33 | } 34 | 35 | if (1) { 36 | let name = "1"; 37 | debugger; 38 | } 39 | 40 | debugger; 41 | } 42 | 43 | // test(); 44 | 45 | 46 | 47 | function recursiveFunc(num) { 48 | 49 | debugger; 50 | if(num === 0) return; 51 | 52 | debugger; 53 | console.log(num); 54 | 55 | return recursiveFunc(num - 1) 56 | } 57 | 58 | 59 | recursiveFunc(5); 60 | -------------------------------------------------------------------------------- /w3/d2/lecture.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | Call Stack! 5 | * The call stack is a structure that js uses to keep track of evaluation of function calls 6 | * function is at the top stack, it is the function currently being executed 7 | * stack data structure 8 | * EX: Stack of plates 9 | * first in last out 10 | * when a function is called, it is pushed on the call stack 11 | * when a function is returned, it is popped off the call stack 12 | 13 | 14 | */ 15 | 16 | // Observe stack 17 | // * Can watch stack using debugger 18 | 19 | function foo() { 20 | console.log("a"); 21 | debugger; 22 | bar(); 23 | console.log("e"); 24 | } 25 | 26 | function bar() { 27 | console.log("b"); 28 | debugger; 29 | baz(); 30 | console.log("d"); 31 | } 32 | 33 | function baz() { 34 | debugger; 35 | console.log("c"); 36 | } 37 | 38 | // foo(); //a,b,c,d,e 39 | 40 | 41 | function test() { 42 | return true; 43 | }; 44 | 45 | // console.log(test());//<---true 46 | -------------------------------------------------------------------------------- /w3/d2/sum-to-n.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a recursive function called `sumToN` that takes in a number and returns 3 | the sum of all the numbers from 0 to that number. Return null for any input 4 | number below 0. 5 | 6 | Examples: 7 | 8 | sumToN(5) // returns 15 9 | sumToN(1) // returns 1 10 | sumToN(9) // returns 45 11 | sumToN(-8) // returns null 12 | ***********************************************************************/ 13 | 14 | 15 | function sumToN(n) { 16 | if (n <= 0) { 17 | return null 18 | } 19 | 20 | return n + sumToN(n - 1); 21 | } 22 | 23 | let example = (num) => num + 5; 24 | // console.log(example(10)); 25 | 26 | console.log(sumToN(5)) // returns 15 27 | /* 28 | sumToN(0) => return null/0 29 | sumToN(1) => 1 30 | sumToN(2) => 3 31 | sumToN(3) => 6 32 | sumToN(4) => 10 33 | 34 | sumToN(5) => 15 35 | */ 36 | console.log(sumToN(1)) // returns 1 37 | console.log(sumToN(9)) // returns 45 38 | console.log(sumToN(-8)) // returns null 39 | // console.log(null + 10);// 10 40 | -------------------------------------------------------------------------------- /w3/d2/tree_recursion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/w3/d2/tree_recursion.png -------------------------------------------------------------------------------- /w3/d3/first_class_obj.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | But what does this all mean? This brings us around to the concept of first 5 | class objects. A first class object is defined as: 6 | * 1. It can be stored in a variable 7 | - function expression 8 | * 2. it can be passed as an argument to a function (coming up next week!) 9 | - callback 10 | * 3. It can be returned from a function (also coming up next week!) 11 | - closure/recursion 12 | 13 | */ 14 | -------------------------------------------------------------------------------- /w3/d3/hoisting.js: -------------------------------------------------------------------------------- 1 | /* 2 | Hoisting! 3 | let, const, and var 4 | - var - hoist the declaration not the assignment, but has a default value of undefined 5 | -const/let - hoist the only declaration but does not have a value, therefore throws an error when trying to access before initialization 6 | Hosting with Functions! 7 | */ 8 | 9 | function hoistVar(){ 10 | console.log(name); // undefined 11 | var name = "Maica" 12 | }; 13 | 14 | // hoistVar(); 15 | 16 | function hoistConstAndLet(){ 17 | console.log(name); // Cannot access 'name' before initialization 18 | // let name = "Maica"; 19 | const name = "Maica"; 20 | } 21 | 22 | // hoistConstAndLet(); 23 | 24 | 25 | // hoist the function delcaration but not the assignment 26 | // notHoisted(); // Cannot access 'notHoisted' before initialization 27 | let notHoisted = () => console.log("function will not get hoisted") 28 | 29 | hoisted(); // hoisted 30 | function hoisted(){ 31 | console.log("hoisted") 32 | } 33 | -------------------------------------------------------------------------------- /w3/d3/iife.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Immediately invoked function expressions 4 | 5 | What is an IIFE? What does it allow us to do? 6 | - Define and immediately run anonymous function 7 | - iife can only be ran once 8 | 9 | How could IFFE be useful? 10 | - Want to run a function one time 11 | - Don't want use the global name space 12 | - Protects function names and variables 13 | */ 14 | 15 | //function expression 16 | //storing in anon function in a variable 17 | //as soon as you do that, it is no longer anonymous 18 | //because we can alias the function with the variable we've stored it within 19 | let sayHi = function(){ 20 | console.log("hello") 21 | } 22 | 23 | // sayHi(); 24 | 25 | //function expression with far arrow 26 | // let sayHi2 = () => console.log("hello 2"); 27 | 28 | // sayHi2(); 29 | 30 | // an iife is an anon portion wrapped in parenthesis 31 | //IIFE 32 | // (function(){ 33 | // console.log("only runs once") 34 | // })() 35 | 36 | // fat arrow syntax 37 | // (()=>console.log("only runs once in fat arrow"))(); 38 | 39 | // prove an iffe runs once 40 | 41 | let sayHi2 = (function(){ 42 | console.log("will only run once"); 43 | return "hello"; 44 | })(); 45 | 46 | console.log(sayHi2); 47 | console.log(sayHi2); 48 | -------------------------------------------------------------------------------- /w3/d3/lecture.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/w3/d3/lecture.js -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt1/README.md: -------------------------------------------------------------------------------- 1 | # Recursion Problems 2 | 3 | Here we `go(go(go()))`! It's time to flex your coding muscles on recursion. For 4 | each problem, implement a **recursive** function that satisfies all the listed 5 | requirements. Iterative solutions will be considered incorrect. The problems 6 | aren't dependent on each other and may be completed in any order you wish. 7 | 8 | As you complete each problem, use `npm test` to test your code. Make sure 9 | you're in the project's root: you should be in the same place as the `problems/` 10 | and `test/` directories. Once there, run the following setup command: 11 | 12 | ```sh 13 | > npm install 14 | ``` 15 | 16 | Whenever you want to test your code, run the following command: 17 | 18 | ```sh 19 | > npm test 20 | ``` 21 | 22 | Having trouble? Reach out to a TA for assistance! 23 | 24 | We know you've got this! 25 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt1/build_trigger.md: -------------------------------------------------------------------------------- 1 | This file is used to manually trigger the build process. It is here to provide 2 | a defined place to commit a trivial change. It may be ignored by students. 3 | 4 | To use, simply add the date and time below and commit to branch->staging->master 5 | as normal. 6 | 7 | 8/3/23 3:56pm ET 8 | 09/01/2023 2:30pm ET 9 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt1/ghapp.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "programs": { 3 | "BP": true, 4 | "FT": true, 5 | "PT": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "recursion-pt1-practice", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "mocha", 7 | "test-with-json": "mocha --reporter json" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "mocha": "^10.2.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt1/problems/01-sum-to-n.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a recursive function called `sumToN` that takes in a number and returns 3 | the sum of all the numbers from 0 to that number. Return null for any input 4 | number below 0. 5 | 6 | Examples: 7 | 8 | sumToN(5) // returns 15 9 | sumToN(1) // returns 1 10 | sumToN(9) // returns 45 11 | sumToN(-8) // returns null 12 | ***********************************************************************/ 13 | 14 | 15 | function sumToN(n) { 16 | //!!START 17 | if (n < 0) return null; 18 | if (n <= 1) return n; 19 | 20 | return n + sumToN(n - 1); 21 | //!!END 22 | } 23 | 24 | 25 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 26 | try { 27 | module.exports = sumToN; 28 | } catch (e) { 29 | module.exports = null; 30 | } 31 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt1/problems/02-sum-array.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a recursive function called `sumArray` that takes an array of integers 3 | and returns the value of all the integers added together. Your array may 4 | include a mix of positive and negative integers! 5 | 6 | Examples: 7 | 8 | sumArray([1, 2, 3]); // 6 9 | sumArray([0, 1, -3]); // -2 10 | sumArray([1, 2, 3, 4, 5]); // 15 11 | ***********************************************************************/ 12 | 13 | function sumArray(arr) { 14 | //!!START 15 | if (arr.length === 0) { 16 | return 0; 17 | } 18 | 19 | return arr[0] + sumArray(arr.slice(1)); 20 | //!!END 21 | } 22 | 23 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 24 | try { 25 | module.exports = sumArray; 26 | } catch (e) { 27 | module.exports = null; 28 | } 29 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt1/problems/04-range.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a recursive function, `range`, that takes a start and an end and returns 3 | an array of all numbers in that range, exclusive. If the end number is less than 4 | the start, return an empty array. 5 | 6 | Examples: 7 | 8 | range(1, 5); // [1, 2, 3, 4] 9 | range(3, 4); // [3] 10 | range(7, 6); // [] 11 | ***********************************************************************/ 12 | 13 | 14 | function range(start, end) { 15 | //!!START 16 | if (end <= start) return []; 17 | 18 | return [start].concat(range(start + 1, end)); 19 | //!!END 20 | } 21 | 22 | 23 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 24 | try { 25 | module.exports = range; 26 | } catch (e) { 27 | module.exports = null; 28 | } 29 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt1/test/01-sum-to-n-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const sumToN = require('../problems/01-sum-to-n'); 4 | 5 | describe("sumToN()", function () { 6 | it("should sum all the numbers from 0 to n", function () { 7 | assert.strictEqual(sumToN(5), 15); 8 | assert.strictEqual(sumToN(1), 1); 9 | assert.strictEqual(sumToN(9), 45); 10 | assert.strictEqual(sumToN(-8), null); 11 | }); 12 | }); -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt1/test/02-sum-array-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const sumArray = require('../problems/02-sum-array'); 4 | 5 | describe("sumArray()", function () { 6 | it("should return the sum of all the elements in the array", function () { 7 | assert.strictEqual(sumArray([1, 2, 3]), 6); 8 | assert.strictEqual(sumArray([0, 1, -3]), -2); 9 | assert.strictEqual(sumArray([1, 2, 3, 4, 5]), 15); 10 | assert.strictEqual(sumArray([5, 4, 3, 2, 1]), 15); 11 | assert.strictEqual(sumArray([0, 0, 1, 0, 0]), 1); 12 | assert.strictEqual(sumArray([-1, -1, -1, -1]), -4); 13 | assert.strictEqual(sumArray([99, 100, 101]), 300); 14 | }); 15 | }); -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt1/test/03-ice-cream-shop-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const iceCreamShop = require('../problems/03-ice-cream-shop'); 4 | 5 | describe("iceCreamShop()", function () { 6 | it("should return true if the favorite ice cream is included in the flavors", function () { 7 | assert.strictEqual(iceCreamShop(['vanilla', 'strawberry'], 'blue moon'), false); 8 | assert.strictEqual(iceCreamShop(['pistachio', 'green tea', 'chocolate', 'mint chip'], 'green tea'), true); 9 | assert.strictEqual(iceCreamShop(['cookies n cream', 'blue moon', 'superman', 'honey lavender', 'sea salt caramel'], 'pistachio'), false); 10 | assert.strictEqual(iceCreamShop(['moose tracks'], 'moose tracks'), true); 11 | assert.strictEqual(iceCreamShop([], 'honey lavender'), false); 12 | }); 13 | }); -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt1/test/04-range-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const range = require('../problems/04-range'); 4 | 5 | describe("range()", function () { 6 | it("should an array of numbers from the start to the end number, not inclusive", function () { 7 | assert.deepStrictEqual(range(1, 5), [1, 2, 3, 4]); 8 | assert.deepStrictEqual(range(3, 4), [3]); 9 | assert.deepStrictEqual(range(7, 6), []); 10 | }); 11 | }); -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt1/test/util/deep-includes-order-matters.js: -------------------------------------------------------------------------------- 1 | // nested includes, but order of nested elements matter 2 | // testing permutations 3 | 4 | function deepIncludesOrderMatters(subs, arr) { 5 | if (subs.length !== arr.length) return false; 6 | let matched = []; 7 | for (let set1 of subs) { 8 | let match = false; 9 | for (let i = 0; i < arr.length; i++) { 10 | if (matched.includes(i)) continue; 11 | const set2 = arr[i]; 12 | if (set1.length !== set2.length) continue; 13 | let elementMatch = true; 14 | for (let j = 0; j < set1.length; j++) { 15 | if (set1[j] !== set2[j]) { 16 | elementMatch = false; 17 | break; 18 | } 19 | } 20 | if (elementMatch) { 21 | matched.push(i); 22 | match = true; 23 | break; 24 | } 25 | } 26 | if (match === false) return false; 27 | } 28 | return true; 29 | } 30 | 31 | module.exports = deepIncludesOrderMatters; -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt1/test/util/deep-includes.js: -------------------------------------------------------------------------------- 1 | // nested includes and nested elements order doesn't matter 2 | // testing subsets 3 | 4 | function deepIncludes(subs, arr) { 5 | if (subs.length !== arr.length) return false; 6 | let matched = []; 7 | for (let set1 of subs) { 8 | let match = false; 9 | for (let i = 0; i < arr.length; i++) { 10 | if (matched.includes(i)) continue; 11 | const set2 = arr[i]; 12 | if (set1.length !== set2.length) continue; 13 | const included = []; 14 | for (let j = 0; j < set1.length; j++) { 15 | for (let k = 0; k < set2.length; k++) { 16 | if (included.includes(k)) continue; 17 | if (set1[j] === set2[k]) included.push(k); 18 | } 19 | } 20 | if (included.length === set1.length) { 21 | matched.push(i); 22 | match = true; 23 | break; 24 | } 25 | } 26 | if (match === false) return false; 27 | } 28 | return true; 29 | } 30 | 31 | module.exports = deepIncludes; -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt2/README.md: -------------------------------------------------------------------------------- 1 | # Recursion Problems 2 | 3 | Here we `go(go(go()))`! It's time to flex your coding muscles on recursion. For 4 | each problem, implement a **recursive** function that satisfies all the listed 5 | requirements. Iterative solutions will be considered incorrect. The problems 6 | aren't dependent on each other and may be completed in any order you wish. 7 | 8 | As you complete each problem, use `npm test` to test your code. Make sure 9 | you're in the project's root: you should be in the same place as the `problems/` 10 | and `test/` directories. Once there, run the following setup command: 11 | 12 | ```sh 13 | > npm install 14 | ``` 15 | 16 | Whenever you want to test your code, run the following command: 17 | 18 | ```sh 19 | > npm test 20 | ``` 21 | 22 | Having trouble? Reach out to a TA for assistance! 23 | 24 | We know you've got this! 25 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt2/build_trigger.md: -------------------------------------------------------------------------------- 1 | This file is used to manually trigger the build process. It is here to provide 2 | a defined place to commit a trivial change. It may be ignored by students. 3 | 4 | To use, simply add the date and time below and commit to branch->staging->master 5 | as normal. 6 | 7 | 8/3/23 3:56pm ET 8 | 09/01/2023 2:30pm ET 9 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt2/ghapp.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "programs": { 3 | "BP": true, 4 | "FT": true, 5 | "PT": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "recursion-pt2-practice", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "mocha", 7 | "test-with-json": "mocha --reporter json" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "mocha": "^10.2.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt2/problems/05-reverse.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a recursive function reverse(string) that takes in a string and returns 3 | it reversed. 4 | 5 | Examples: 6 | 7 | reverse("house"); // "esuoh" 8 | reverse("dog"); // "god" 9 | reverse("atom"); // "mota" 10 | reverse("q"); // "q" 11 | reverse("id"); // "di" 12 | reverse(""); // "" 13 | ***********************************************************************/ 14 | 15 | 16 | function reverse(str) { 17 | //!!START 18 | if (!str.length) return str; 19 | 20 | return reverse(str.slice(1)) + str[0]; 21 | //!!END 22 | } 23 | 24 | 25 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 26 | try { 27 | module.exports = reverse; 28 | } catch (e) { 29 | module.exports = null; 30 | } 31 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt2/problems/06-add-to-twelve.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a recursive function called `addToTwelve` that will return true if there 3 | are two adjacent numbers in the input array that can sum up to 12. Otherwise, 4 | return false. 5 | 6 | Examples: 7 | 8 | addToTwelve([1, 3, 4, 7, 5]); // true 9 | addToTwelve([1, 3, 4, 7, 6]); // false 10 | addToTwelve([1, 11, 4, 7, 6]); // true 11 | addToTwelve([1, 12, 4, 7, 6]); // false 12 | addToTwelve([1]); // false 13 | ***********************************************************************/ 14 | 15 | 16 | function addToTwelve(arr) { 17 | //!!START 18 | if (arr.length < 2) return false; 19 | if (arr[0] + arr[1] === 12) return true; 20 | 21 | return addToTwelve(arr.slice(1)); 22 | //!!END 23 | } 24 | 25 | 26 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 27 | try { 28 | module.exports = addToTwelve; 29 | } catch (e) { 30 | module.exports = null; 31 | } 32 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt2/test/05-reverse-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const reverse = require('../problems/05-reverse'); 4 | 5 | describe("reverse()", function () { 6 | it("should return the string reversed", function () { 7 | assert.strictEqual(reverse("house"), "esuoh"); 8 | assert.strictEqual(reverse("dog"), "god"); 9 | assert.strictEqual(reverse("atom"), "mota"); 10 | assert.strictEqual(reverse("q"), "q"); 11 | assert.strictEqual(reverse("id"), "di"); 12 | assert.strictEqual(reverse(""), ""); 13 | }); 14 | }); -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt2/test/06-add-to-twelve-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const addToTwelve = require('../problems/06-add-to-twelve'); 4 | 5 | describe("addToTwelve()", function () { 6 | it("should return true if there are two adjacent numbers in the array that sum to 12", function () { 7 | assert.strictEqual(addToTwelve([1, 3, 4, 7, 5]), true); 8 | assert.strictEqual(addToTwelve([1, 3, 4, 7, 6]), false); 9 | assert.strictEqual(addToTwelve([1, 11, 4, 7, 6]), true); 10 | assert.strictEqual(addToTwelve([1, 12, 4, 7, 6]), false); 11 | assert.strictEqual(addToTwelve([1]), false); 12 | }); 13 | }); -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt2/test/07-exponent-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const exponent = require('../problems/07-exponent'); 4 | 5 | describe("exponent()", function () { 6 | it("should return the base number to the n power", function () { 7 | assert.strictEqual(exponent(3, 2), 9); 8 | assert.strictEqual(exponent(2, -2), 0.25); 9 | assert.strictEqual(exponent(5, 5), 3125); 10 | assert.equal(exponent(3, 3), 27); 11 | assert.equal(exponent(-2, 2), 4); 12 | assert.equal(exponent(0, 10), 0); 13 | assert.equal(exponent(10, 10), 10000000000); 14 | }); 15 | }); -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt2/test/util/deep-includes-order-matters.js: -------------------------------------------------------------------------------- 1 | // nested includes, but order of nested elements matter 2 | // testing permutations 3 | 4 | function deepIncludesOrderMatters(subs, arr) { 5 | if (subs.length !== arr.length) return false; 6 | let matched = []; 7 | for (let set1 of subs) { 8 | let match = false; 9 | for (let i = 0; i < arr.length; i++) { 10 | if (matched.includes(i)) continue; 11 | const set2 = arr[i]; 12 | if (set1.length !== set2.length) continue; 13 | let elementMatch = true; 14 | for (let j = 0; j < set1.length; j++) { 15 | if (set1[j] !== set2[j]) { 16 | elementMatch = false; 17 | break; 18 | } 19 | } 20 | if (elementMatch) { 21 | matched.push(i); 22 | match = true; 23 | break; 24 | } 25 | } 26 | if (match === false) return false; 27 | } 28 | return true; 29 | } 30 | 31 | module.exports = deepIncludesOrderMatters; -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt2/test/util/deep-includes.js: -------------------------------------------------------------------------------- 1 | // nested includes and nested elements order doesn't matter 2 | // testing subsets 3 | 4 | function deepIncludes(subs, arr) { 5 | if (subs.length !== arr.length) return false; 6 | let matched = []; 7 | for (let set1 of subs) { 8 | let match = false; 9 | for (let i = 0; i < arr.length; i++) { 10 | if (matched.includes(i)) continue; 11 | const set2 = arr[i]; 12 | if (set1.length !== set2.length) continue; 13 | const included = []; 14 | for (let j = 0; j < set1.length; j++) { 15 | for (let k = 0; k < set2.length; k++) { 16 | if (included.includes(k)) continue; 17 | if (set1[j] === set2[k]) included.push(k); 18 | } 19 | } 20 | if (included.length === set1.length) { 21 | matched.push(i); 22 | match = true; 23 | break; 24 | } 25 | } 26 | if (match === false) return false; 27 | } 28 | return true; 29 | } 30 | 31 | module.exports = deepIncludes; -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt3/README.md: -------------------------------------------------------------------------------- 1 | # Recursion Problems 2 | 3 | Here we `go(go(go()))`! It's time to flex your coding muscles on recursion. For 4 | each problem, implement a **recursive** function that satisfies all the listed 5 | requirements. Iterative solutions will be considered incorrect. The problems 6 | aren't dependent on each other and may be completed in any order you wish. 7 | 8 | As you complete each problem, use `npm test` to test your code. Make sure 9 | you're in the project's root: you should be in the same place as the `problems/` 10 | and `test/` directories. Once there, run the following setup command: 11 | 12 | ```sh 13 | > npm install 14 | ``` 15 | 16 | Whenever you want to test your code, run the following command: 17 | 18 | ```sh 19 | > npm test 20 | ``` 21 | 22 | Having trouble? Reach out to a TA for assistance! 23 | 24 | We know you've got this! 25 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt3/build_trigger.md: -------------------------------------------------------------------------------- 1 | This file is used to manually trigger the build process. It is here to provide 2 | a defined place to commit a trivial change. It may be ignored by students. 3 | 4 | To use, simply add the date and time below and commit to branch->staging->master 5 | as normal. 6 | 7 | 8/3/23 3:56pm ET 8 | 09/01/2023 2:30pm ET 9 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt3/ghapp.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "programs": { 3 | "BP": true, 4 | "FT": true, 5 | "PT": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt3/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "solution", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha", 11 | "test-with-json": "mocha --reporter json" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "dependencies": { 17 | "chai": "^4.2.0", 18 | "chai-spies": "^1.0.0", 19 | "mocha": "^6.2.2" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt3/problems/09-fibonacci.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a recursive function called `fibonacci` that takes an integer, `n`, 3 | and returns the `n`th number in the Fibonacci sequence. 4 | 5 | Not familiar with the Fibonacci sequence? Beginning with 0 and 1, we add the two 6 | previous numbers in the sequence together to form the next one: 7 | 8 | 0, 1, 1, 2, 3, 5, 8, etc.... 9 | 10 | We count Fibonacci numbers beginning with the first 1. Take a look at the 11 | examples below if you're unsure where to start! 12 | 13 | Examples: 14 | 15 | fibonacci(1); // 1 16 | fibonacci(2); // 1 17 | fibonacci(3); // 2 18 | fibonacci(4); // 3 19 | fibonacci(10); // 55 20 | ***********************************************************************/ 21 | 22 | function fibonacci(n) { 23 | //!!START 24 | if (n === 1 || n === 2) { 25 | return 1; 26 | } 27 | 28 | return fibonacci(n - 1) + fibonacci(n - 2); 29 | //!!END 30 | }; 31 | 32 | 33 | console.log(fibonacci(6));// 8 34 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 35 | module.exports = fibonacci; 36 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt3/problems/10-factorial.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a recursive function called `factorial` that takes an integer, `num`, 3 | and returns the factorial of `num`. Assume the value of `num` is greater 4 | than or equal to 1. 5 | 6 | A factorial is the number get when multiplying a number by itself minus one 7 | all the way down to 1 (but not 0)! We represent them with an exclamation 8 | point, also sometimes called a "bang" in programming. 9 | 10 | 5! = 5 x 4 x 3 x 2 x 1 = 120 11 | 12 | Examples: 13 | 14 | factorial(1); // 1 15 | factorial(3); // 6 16 | factorial(5); // 120 17 | ***********************************************************************/ 18 | 19 | function factorial(num) { 20 | //!!START 21 | if (num === 1) { 22 | return 1; 23 | } 24 | 25 | return num * factorial(num - 1); 26 | //!!END 27 | } 28 | 29 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 30 | module.exports = factorial; 31 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt3/problems/12-is-sorted.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a recursive solution called `isSorted` to determine if the input array 3 | is sorted in ascending order. 4 | 5 | Examples: 6 | 7 | isSorted([1, 2, 3, 4, 5]); // true 8 | isSorted([1, 2, 4, 3, 5]); // false 9 | isSorted([2, 4, 6, 7, 8]); // true 10 | isSorted([5, 4, 3, 2, 1]); // false 11 | ***********************************************************************/ 12 | 13 | 14 | function isSorted(arr) { 15 | //!!START 16 | if (arr.length < 2) return true; 17 | if (arr[0] > arr[1]) return false; 18 | return isSorted(arr.slice(1)); 19 | //!!END 20 | } 21 | 22 | 23 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 24 | try { 25 | module.exports = isSorted; 26 | } catch (e) { 27 | module.exports = null; 28 | } 29 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt3/test/09-fibonacci-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const fibonacci = require('../problems/09-fibonacci'); 4 | 5 | describe("fibonacci()", function () { 6 | it("should return the expected nth Fibonacci number", function () { 7 | assert.strictEqual(fibonacci(1), 1); 8 | assert.strictEqual(fibonacci(2), 1); 9 | assert.strictEqual(fibonacci(3), 2); 10 | assert.strictEqual(fibonacci(4), 3); 11 | assert.strictEqual(fibonacci(10), 55); 12 | assert.strictEqual(fibonacci(5), 5); 13 | assert.strictEqual(fibonacci(20), 6765); 14 | }); 15 | }); -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt3/test/10-factorial-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const factorial = require('../problems/10-factorial'); 4 | 5 | describe("factorial()", function () { 6 | it("should return the expected factorial for a given number", function () { 7 | assert.equal(factorial(1), 1); 8 | assert.equal(factorial(3), 6); 9 | assert.equal(factorial(5), 120); 10 | assert.equal(factorial(2), 2); 11 | assert.equal(factorial(6), 720); 12 | assert.equal(factorial(10), 3628800); 13 | }); 14 | }); -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt3/test/11-flatten-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const chai = require("chai"); 3 | const expect = chai.expect; 4 | const spies = require("chai-spies"); 5 | chai.use(spies); 6 | 7 | const flatten = require('../problems/11-flatten'); 8 | 9 | describe("flatten()", function () { 10 | it("should return the all the nested array contents in a single array", function () { 11 | assert.deepEqual(flatten([]), []); 12 | assert.deepEqual(flatten([1, 2]), [1, 2]); 13 | assert.deepEqual(flatten([1, [2, [3]]]), [1, 2, 3]); 14 | assert.deepEqual(flatten([[[[]]]]), []); 15 | assert.deepEqual( 16 | flatten([ 17 | [1, 2], 18 | [3, [4, 5]], 19 | ]), 20 | [1, 2, 3, 4, 5] 21 | ); 22 | assert.deepEqual(flatten([[[1, 2]], [[3, 4]]]), [1, 2, 3, 4]); 23 | }); 24 | it("should not call the Array.prototype.flat() method", function () { 25 | const flatSpy = chai.spy.on(Array.prototype, "flat"); 26 | assert.deepEqual(flatten([[[[]]]]), []); 27 | expect(flatSpy).to.have.not.been.called(); 28 | }) 29 | }); -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt3/test/12-is-sorted-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const isSorted = require('../problems/12-is-sorted'); 4 | 5 | describe("isSorted()", function () { 6 | it("should return true if the array is sorted, else false", function () { 7 | assert.strictEqual(isSorted([1, 2, 3, 4, 5]), true); 8 | assert.strictEqual(isSorted([1, 2, 4, 3, 5]), false); 9 | assert.strictEqual(isSorted([2, 4, 6, 7, 8]), true); 10 | assert.strictEqual(isSorted([5, 4, 3, 2, 1]), false); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt3/test/util/deep-includes-order-matters.js: -------------------------------------------------------------------------------- 1 | // nested includes, but order of nested elements matter 2 | // testing permutations 3 | 4 | function deepIncludesOrderMatters(subs, arr) { 5 | if (subs.length !== arr.length) return false; 6 | let matched = []; 7 | for (let set1 of subs) { 8 | let match = false; 9 | for (let i = 0; i < arr.length; i++) { 10 | if (matched.includes(i)) continue; 11 | const set2 = arr[i]; 12 | if (set1.length !== set2.length) continue; 13 | let elementMatch = true; 14 | for (let j = 0; j < set1.length; j++) { 15 | if (set1[j] !== set2[j]) { 16 | elementMatch = false; 17 | break; 18 | } 19 | } 20 | if (elementMatch) { 21 | matched.push(i); 22 | match = true; 23 | break; 24 | } 25 | } 26 | if (match === false) return false; 27 | } 28 | return true; 29 | } 30 | 31 | module.exports = deepIncludesOrderMatters; -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt3/test/util/deep-includes.js: -------------------------------------------------------------------------------- 1 | // nested includes and nested elements order doesn't matter 2 | // testing subsets 3 | 4 | function deepIncludes(subs, arr) { 5 | if (subs.length !== arr.length) return false; 6 | let matched = []; 7 | for (let set1 of subs) { 8 | let match = false; 9 | for (let i = 0; i < arr.length; i++) { 10 | if (matched.includes(i)) continue; 11 | const set2 = arr[i]; 12 | if (set1.length !== set2.length) continue; 13 | const included = []; 14 | for (let j = 0; j < set1.length; j++) { 15 | for (let k = 0; k < set2.length; k++) { 16 | if (included.includes(k)) continue; 17 | if (set1[j] === set2[k]) included.push(k); 18 | } 19 | } 20 | if (included.length === set1.length) { 21 | matched.push(i); 22 | match = true; 23 | break; 24 | } 25 | } 26 | if (match === false) return false; 27 | } 28 | return true; 29 | } 30 | 31 | module.exports = deepIncludes; -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt4/README.md: -------------------------------------------------------------------------------- 1 | # Recursion Problems 2 | 3 | Here we `go(go(go()))`! It's time to flex your coding muscles on recursion. For 4 | each problem, implement a **recursive** function that satisfies all the listed 5 | requirements. Iterative solutions will be considered incorrect. The problems 6 | aren't dependent on each other and may be completed in any order you wish. 7 | 8 | As you complete each problem, use `npm test` to test your code. Make sure 9 | you're in the project's root: you should be in the same place as the `problems/` 10 | and `test/` directories. Once there, run the following setup command: 11 | 12 | ```sh 13 | > npm install 14 | ``` 15 | 16 | Whenever you want to test your code, run the following command: 17 | 18 | ```sh 19 | > npm test 20 | ``` 21 | 22 | Having trouble? Reach out to a TA for assistance! 23 | We know you've got this! -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt4/build_trigger.md: -------------------------------------------------------------------------------- 1 | This file is used to manually trigger the build process. It is here to provide 2 | a defined place to commit a trivial change. It may be ignored by students. 3 | 4 | To use, simply add the date and time below and commit to branch->staging->master 5 | as normal. 6 | 7 | 8/3/23 3:56pm ET 8 | 09/01/2023 2:30pm ET 9 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt4/ghapp.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "programs": { 3 | "BP": true, 4 | "FT": true, 5 | "PT": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt4/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "recursion-pt4-practice", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "mocha", 7 | "test-with-json": "mocha --reporter json" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "mocha": "^10.2.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt4/test/13-sort-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const sort = require('../problems/13-sort'); 4 | 5 | describe("sort()", function () { 6 | it("should sort an array of numbers from least to greatest", function () { 7 | assert.deepEqual(sort([4, 1, 6, 3, 1, 7]), [1, 1, 3, 4, 6, 7]); 8 | assert.deepEqual(sort([0, 1, -3]), [-3, 0, 1]); 9 | assert.deepEqual(sort([]), []); 10 | assert.deepEqual(sort([-5.5, -10, 100, 0]), [-10, -5.5, 0, 100]); 11 | assert.deepEqual(sort([5, 2, 18, 6, 8]), [2, 5, 6, 8, 18]); 12 | assert.deepEqual(sort([10, 10, 20, 20, 5, 5, 1, 1]), [1, 1, 5, 5, 10, 10, 20, 20]); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt4/test/14-deep-dup-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const deepDup = require('../problems/14-deep-dup'); 4 | 5 | describe("deepDup()", function () { 6 | it("should return a deep duplicated version of the given array", function () { 7 | let arr = [1, 2, 3]; 8 | let duped = deepDup(arr); // [1, 2, 3] 9 | assert.deepStrictEqual(duped, [1, 2, 3]); 10 | assert.strictEqual(arr === duped, false); 11 | 12 | arr = [1, [2, [3]]]; 13 | duped = deepDup(arr); // [1, [2, [3]]] 14 | assert.deepStrictEqual(duped, [1, [2, [3]]]); 15 | assert.strictEqual(arr === duped, false); 16 | assert.strictEqual(arr[1] === duped[1], false); 17 | assert.strictEqual(arr[1][1] === duped[1][1], false); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt4/test/15-subsets-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const subsets = require('../problems/15-bonus-subsets'); 4 | const deepIncludes = require('./util/deep-includes'); 5 | 6 | describe("subsets()", function () { 7 | it("should return all the subsets of the given array", function () { 8 | assert.strictEqual(deepIncludes(subsets([]), [[]]), true); 9 | assert.strictEqual(deepIncludes(subsets([1]), [[], [1]]), true); 10 | assert.strictEqual(deepIncludes(subsets([1, 2]), [[], [1], [2], [1, 2]]), true); 11 | assert.strictEqual(deepIncludes(subsets([1, 2]), [[1], [2], [1, 2]]), false); 12 | assert.strictEqual(deepIncludes(subsets([1, 2]), [[], [1, 2], [2], [1, 2]]), false); 13 | assert.strictEqual(deepIncludes(subsets([1, 2, 3]), [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]), true); 14 | }); 15 | }); -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt4/test/17-permutations-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const permutations = require("../problems/17-bonus-permutations.js"); 4 | const deepIncludes = require('./util/deep-includes-order-matters'); 5 | 6 | describe("permutations()", function () { 7 | it("should return all the permutations of the given array", function () { 8 | assert.strictEqual(deepIncludes(permutations([1, 2]), 9 | [[1, 2], 10 | [2, 1]] 11 | ), true); 12 | assert.strictEqual(deepIncludes(permutations([1, 2]), 13 | [[1, 2], 14 | [2, 3]] 15 | ), false); 16 | assert.strictEqual(deepIncludes(permutations([1, 2]), 17 | [[1, 2], 18 | [1, 2]] 19 | ), false); 20 | assert.strictEqual(deepIncludes(permutations([1, 2, 3]), 21 | [[1, 2, 3], [1, 3, 2], 22 | [2, 1, 3], [2, 3, 1], 23 | [3, 1, 2], [3, 2, 1]] 24 | ), true); 25 | assert.strictEqual(deepIncludes(permutations([1, 2, 3]), 26 | [[2, 1, 3], [2, 3, 1], 27 | [1, 2, 3], [1, 3, 2], 28 | [3, 1, 2], [3, 2, 1]] 29 | ), true); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt4/test/18-make-change-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | 3 | const makeBetterChange = require("../problems/18-bonus-make-change.js"); 4 | 5 | function includesEqual(arr1, arr2) { 6 | if (arr1.length !== arr2.length) return false; 7 | let matches = []; 8 | for (let ele1 of arr1) { 9 | let matched = false; 10 | for (let i = 0; i < arr2.length; i++) { 11 | if (matches.includes(i)) continue; 12 | const ele2 = arr2[i]; 13 | if (ele1 === ele2) { 14 | matches.push(i); 15 | matched = true; 16 | break; 17 | } 18 | } 19 | if (!matched) return false 20 | } 21 | return true; 22 | } 23 | 24 | describe("makeBetterChange()", function () { 25 | it("should return the best way to make change for the given target amount", function () { 26 | assert.strictEqual(includesEqual(makeBetterChange(21), [1, 10, 10]), true); 27 | assert.strictEqual(includesEqual(makeBetterChange(75), [25, 25, 25]), true); 28 | assert.strictEqual(includesEqual(makeBetterChange(33, [15, 3]), [3, 15, 15]), true); 29 | assert.strictEqual(makeBetterChange(34, [15, 3]), null); 30 | assert.strictEqual(includesEqual(makeBetterChange(24, [10, 7, 1]), [7, 7, 10]), true); 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt4/test/util/deep-includes-order-matters.js: -------------------------------------------------------------------------------- 1 | // nested includes, but order of nested elements matter 2 | // testing permutations 3 | 4 | function deepIncludesOrderMatters(subs, arr) { 5 | if (subs.length !== arr.length) return false; 6 | let matched = []; 7 | for (let set1 of subs) { 8 | let match = false; 9 | for (let i = 0; i < arr.length; i++) { 10 | if (matched.includes(i)) continue; 11 | const set2 = arr[i]; 12 | if (set1.length !== set2.length) continue; 13 | let elementMatch = true; 14 | for (let j = 0; j < set1.length; j++) { 15 | if (set1[j] !== set2[j]) { 16 | elementMatch = false; 17 | break; 18 | } 19 | } 20 | if (elementMatch) { 21 | matched.push(i); 22 | match = true; 23 | break; 24 | } 25 | } 26 | if (match === false) return false; 27 | } 28 | return true; 29 | } 30 | 31 | module.exports = deepIncludesOrderMatters; -------------------------------------------------------------------------------- /w3/d3/solutions/recursion-pt4/test/util/deep-includes.js: -------------------------------------------------------------------------------- 1 | // nested includes and nested elements order doesn't matter 2 | // testing subsets 3 | 4 | function deepIncludes(subs, arr) { 5 | if (subs.length !== arr.length) return false; 6 | let matched = []; 7 | for (let set1 of subs) { 8 | let match = false; 9 | for (let i = 0; i < arr.length; i++) { 10 | if (matched.includes(i)) continue; 11 | const set2 = arr[i]; 12 | if (set1.length !== set2.length) continue; 13 | const included = []; 14 | for (let j = 0; j < set1.length; j++) { 15 | for (let k = 0; k < set2.length; k++) { 16 | if (included.includes(k)) continue; 17 | if (set1[j] === set2[k]) included.push(k); 18 | } 19 | } 20 | if (included.length === set1.length) { 21 | matched.push(i); 22 | match = true; 23 | break; 24 | } 25 | } 26 | if (match === false) return false; 27 | } 28 | return true; 29 | } 30 | 31 | module.exports = deepIncludes; -------------------------------------------------------------------------------- /w3/d4/images/threading.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-1-Resources/6adec4f2ed17a20d8f287a1c37770575f49ddb46/w3/d4/images/threading.png -------------------------------------------------------------------------------- /w3/d4/setInterval.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | 5 | What is setInterval! 6 | * The setInterval() method, offered on the Window and Worker interfaces, repeatedly calls a function or executes a code snippet, with a fixed time delay between each call 7 | * Very similar to setTimeout 8 | * Takes in the same args 9 | * setInterval(callbackfFn, delayInMilliseconds, param1, param2); 10 | * executes a function repeatedly after specified delay 11 | 12 | What does a setInterval return? 13 | * The returned intervalID is a numeric, non-zero value which identifies the timer created by the call to setInterval(); this value can be passed to clearInterval() to cancel the interval. 14 | 15 | */ 16 | 17 | 18 | 19 | // setInterval(console.log, 1000, `im hungry`) 20 | 21 | // setInterval((name) => console.log(`hello ${name}`), 2000, 'maica') 22 | 23 | let hello = (name) => console.log(`hello ${name}`) 24 | 25 | // setInterval(hello, 2000, 'maica'); 26 | 27 | // let timerId = setInterval(hello, 2000, 'maica'); 28 | // console.log(timerId) 29 | 30 | 31 | function time(count){ 32 | debugger; 33 | let timerId = setInterval(() => { 34 | debugger; 35 | count--; 36 | console.log(count); 37 | if(count === 0) return clearInterval(timerId); 38 | }, 1000) 39 | }; 40 | 41 | time(15) 42 | -------------------------------------------------------------------------------- /w3/d4/solutions/timeout-pt1/README.md: -------------------------------------------------------------------------------- 1 | # Timeout Project 2 | 3 | Time to practice dealing with asynchronous functions like `setTimeout` and 4 | `setInterval`. Your objective is to implement the functions in each file 5 | of the `/problems` directory. In addition to the prompts available at the 6 | top of each file, test specs are provided to test your work. 7 | 8 | To get started, use the following commands: 9 | 10 | 1. `cd` into the project directory 11 | 2. `npm install` to install any dependencies 12 | 3. `npm test` to run the test cases 13 | 14 | **Important Note:** 15 | It is very helpful to run each node file with `console.log`s to observe the 16 | behavior of your code and help with debugging. However, **you MUST comment out 17 | any local test cases** that you add to the problem files before running the 18 | tests, because additional logs may cause the tests to fail. 19 | -------------------------------------------------------------------------------- /w3/d4/solutions/timeout-pt1/build_trigger.md: -------------------------------------------------------------------------------- 1 | This file is used to manually trigger the build process. It is here to provide 2 | a defined place to commit a trivial change. It may be ignored by students. 3 | 4 | To use, simply add the date and time below and commit to branch->staging->master 5 | as normal. 6 | 7 | 8/3/23 3:56pm ET 8 | 09/01/2023 2:30pm ET 9 | -------------------------------------------------------------------------------- /w3/d4/solutions/timeout-pt1/ghapp.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "programs": { 3 | "BP": true, 4 | "FT": true, 5 | "PT": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /w3/d4/solutions/timeout-pt1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "solution", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha", 11 | "test-with-json": "mocha --reporter json" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "dependencies": { 17 | "chai": "^4.2.0", 18 | "chai-spies": "^1.0.0", 19 | "mocha": "^6.2.2" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /w3/d4/solutions/timeout-pt1/problems/04-interval-count.js: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Write a function, `intervalCount`, that accepts a callback, a delay in 3 | milliseconds, and an amount. The function should set an interval with 4 | the given callback and delay, but clear the interval after the callback 5 | has been executed 'amount' number of times. 6 | 7 | Hint: utilize a 'closure' to your advantage 8 | 9 | In addition to Mocha, we recommend that you test your code manually using 10 | node with the examples below. 11 | 12 | Example 13 | 14 | intervalCount(function() { 15 | console.log('hi'); 16 | }, 500, 3); // prints 'hi' at 500ms intervals a total of 3 times 17 | ***********************************************************************/ 18 | 19 | function intervalCount(cb, delay, amount) { 20 | //!!START 21 | const interval = setInterval(function() { 22 | cb(); 23 | amount--; 24 | if (amount === 0) { 25 | clearInterval(interval); 26 | } 27 | }, delay); 28 | //!!END 29 | } 30 | 31 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 32 | try { 33 | module.exports = intervalCount; 34 | } catch { 35 | module.exports = null; 36 | } 37 | -------------------------------------------------------------------------------- /w3/d4/solutions/timeout-pt1/test/01-set-seconds-timeout-spec.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const expect = chai.expect; 3 | const spies = require("chai-spies"); 4 | chai.use(spies); 5 | 6 | const setSecondsTimeout = require("../problems/01-set-seconds-timeout.js"); 7 | 8 | describe("setSecondsTimeout()", function() { 9 | let timeoutSpy; 10 | 11 | beforeEach(function() { 12 | timeoutSpy = chai.spy.on(global, "setTimeout", () => null); 13 | }); 14 | 15 | afterEach(function() { 16 | chai.spy.restore(global); 17 | }); 18 | 19 | context("when the delay arg is 1 second", function() { 20 | it("should set a timeout on the callback for 1000ms", function() { 21 | const callback = () => null; 22 | setSecondsTimeout(callback, 1); 23 | expect(timeoutSpy).to.have.been.called.once.with.exactly(callback, 1000); 24 | }); 25 | }); 26 | 27 | context("when the delay arg is 1.4 seconds", function() { 28 | it("should set a timeout on the callback for 1400ms", function() { 29 | const callback = () => null; 30 | setSecondsTimeout(callback, 1.4); 31 | expect(timeoutSpy).to.have.been.called.once.with.exactly(callback, 1400); 32 | }); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /w3/d4/solutions/timeout-pt2/README.md: -------------------------------------------------------------------------------- 1 | # Timeout Project 2 | 3 | Time to practice dealing with asynchronous functions like `setTimeout` and 4 | `setInterval`. Your objective is to implement the functions in each file 5 | of the `/problems` directory. In addition to the prompts available at the 6 | top of each file, test specs are provided to test your work. 7 | 8 | To get started, use the following commands: 9 | 10 | 1. `cd` into the project directory 11 | 2. `npm install` to install any dependencies 12 | 3. `npm test` to run the test cases 13 | 14 | **Important Note:** 15 | It is very helpful to run each node file with `console.log`s to observe the 16 | behavior of your code and help with debugging. However, **you MUST comment out 17 | any local test cases** that you add to the problem files before running the 18 | tests, because additional logs may cause the tests to fail. 19 | -------------------------------------------------------------------------------- /w3/d4/solutions/timeout-pt2/build_trigger.md: -------------------------------------------------------------------------------- 1 | This file is used to manually trigger the build process. It is here to provide 2 | a defined place to commit a trivial change. It may be ignored by students. 3 | 4 | To use, simply add the date and time below and commit to branch->staging->master 5 | as normal. 6 | 7 | 8/3/23 3:56pm ET 8 | 09/01/2023 2:30pm ET 9 | -------------------------------------------------------------------------------- /w3/d4/solutions/timeout-pt2/ghapp.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "programs": { 3 | "BP": true, 4 | "FT": true, 5 | "PT": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /w3/d4/solutions/timeout-pt2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "solution", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha", 11 | "test-with-json": "mocha --reporter json" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "dependencies": { 17 | "chai": "^4.2.0", 18 | "chai-spies": "^1.0.0", 19 | "mocha": "^6.2.2" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /w3/d4/solutions/timeout-pt2/test/05-postpone-spec.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const expect = chai.expect; 3 | const spies = require("chai-spies"); 4 | chai.use(spies); 5 | 6 | const postpone = require("../problems/05-postpone.js"); 7 | 8 | describe("postpone()", function() { 9 | afterEach(function() { 10 | chai.spy.restore(global); 11 | }); 12 | 13 | it("should return a function", function() { 14 | expect(postpone(() => null, 1000)).to.be.a("function"); 15 | }); 16 | 17 | it("should return a function that executes the callback after the given delay when it is called", function(done) { 18 | const setTimeoutSpy = chai.spy.on(global, "setTimeout"); 19 | const callbackSpy = chai.spy(() => { 20 | expect(setTimeoutSpy).to.have.been.called.once.with(250); 21 | expect(callbackSpy).to.have.been.called.once; 22 | done(); 23 | }); 24 | postpone(callbackSpy, 250)(); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /w3/d5/aa03-assessment-practice-01-most-frequent-vowel/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "week-3-unit-test-problems", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha", 11 | "test-with-json": "mocha --reporter json" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "dependencies": { 17 | "chai": "^4.2.0", 18 | "chai-spies": "^1.0.0", 19 | "mocha": "^7.0.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /w3/d5/aa03-assessment-practice-02-print-outer-nums-first/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "week-3-unit-test-problems", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha", 11 | "test-with-json": "mocha --reporter json" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "dependencies": { 17 | "chai": "^4.2.0", 18 | "chai-spies": "^1.0.0", 19 | "mocha": "^7.0.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /w3/d5/aa03-assessment-practice-03-eliminate-type/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "week-3-unit-test-problems", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha", 11 | "test-with-json": "mocha --reporter json" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "dependencies": { 17 | "chai": "^4.2.0", 18 | "chai-spies": "^1.0.0", 19 | "mocha": "^7.0.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /w3/d5/aa03-assessment-practice-03-eliminate-type/test/03-eliminate-type-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const eliminateType = require("../problems/03-eliminate-type.js"); 3 | 4 | describe("eliminateType()", function() { 5 | it("should return a function", function() { 6 | assert.equal(eliminateType([]) instanceof Function, true) 7 | }); 8 | 9 | it("should remove the specified type from the array", function() { 10 | const eliminate = eliminateType([2, undefined, 'world', { color: 'red' }, true, 3, [4, 5], 'hello', false]); 11 | assert.deepStrictEqual( 12 | eliminate('number'), 13 | [undefined, 'world', { color: 'red' }, true, [4, 5], 'hello', false] 14 | ); 15 | assert.deepStrictEqual( 16 | eliminate('object'), 17 | [2, undefined, 'world', true, 3, 'hello', false] 18 | ); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /w3/d5/aa03-assessment-practice-04-print-and-pause/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "week-3-unit-test-problems", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha", 11 | "test-with-json": "mocha --reporter json" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "dependencies": { 17 | "chai": "^4.2.0", 18 | "chai-spies": "^1.0.0", 19 | "mocha": "^7.0.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /w3/d5/free_response.js: -------------------------------------------------------------------------------- 1 | /* 1. Event Loop 2 | 3 | Event loop consists of the message queue and the call stack 4 | The Call Stack handles synchronous code, message queue handles async code, and the event loop 5 | will track both of those structures and will only dequeue and event from the message queue when the call 6 | stack is empty. 7 | */ 8 | 9 | 10 | /* 2. Why Async? 11 | 12 | synchronous code has a guaranteed order while async doesn't. 13 | 14 | Delay executions to allow the user to do different things at the same time. 15 | 16 | ex: when requesting data from an external server over a network, we cannot predict 17 | when we will get a response back. 18 | a lot of things can affect this like traffic on the network, the server being 19 | busy handling other requests and more. 20 | 21 | ex: the human element. users interacting with our programs, hitting keys, 22 | clicking a button, scrolling, whatever. 23 | we don't know what order they'll do them in. 24 | 25 | */ 26 | 27 | /* 3. First Class Objects in JS 28 | 29 | 1. Can be stored in a variable 30 | 2. Passed as an argument 31 | 3. Returned from a function 32 | 33 | ** Key take away, you can treat functions like any other data type. 34 | 35 | */ 36 | -------------------------------------------------------------------------------- /w3/d5/scratch.js: -------------------------------------------------------------------------------- 1 | // if ("") { 2 | // console.log("hi") 3 | // } 4 | 5 | console.log(sayGoodbye("Jeff")); 6 | 7 | const sayGoodbye = function(name) { 8 | return `Goodbye ${name}`; 9 | } 10 | -------------------------------------------------------------------------------- /w3/d5/solutions/bonus-practices/additional-practice/README.md: -------------------------------------------------------------------------------- 1 | # Additional Problems 2 | 3 | If you're reading this, that means you're here for more recursion and async 4 | fun! 5 | 6 | Remember to use `npm test` to test your solutions as you go along. To run the 7 | tests, use the following commands: 8 | 9 | 1. `cd` into the project directory 10 | 2. `npm install` to install any dependencies 11 | 3. `npm test` to run the test cases 12 | -------------------------------------------------------------------------------- /w3/d5/solutions/bonus-practices/additional-practice/build_trigger.md: -------------------------------------------------------------------------------- 1 | This file is used to manually trigger the build process. It is here to provide 2 | a defined place to commit a trivial change. It may be ignored by students. 3 | 4 | To use, simply add the date and time below and commit to branch->staging->master 5 | as normal. 6 | 7 | 8/3/23 3:56pm ET 8 | 09/01/2023 2:30pm ET 9 | -------------------------------------------------------------------------------- /w3/d5/solutions/bonus-practices/additional-practice/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "additional-practice", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha", 11 | "test-with-json": "mocha --reporter json" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "dependencies": { 17 | "chai": "^4.2.0", 18 | "chai-spies": "^1.0.0", 19 | "mocha": "^6.2.2" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /w3/d5/solutions/bonus-practices/additional-practice/problems/02-recursive-sort.js: -------------------------------------------------------------------------------- 1 | /* 2 | Recursive Sort 3 | 4 | Given an array of numbers, write a function that returns a new array of numbers sorted from lowest to highest. 5 | 6 | console.log(sort([])) // prints [] 7 | console.log(sort([9])) // prints [9] 8 | console.log(sort([5, 4, 3, 2, 1])) // prints [1, 2, 3, 4, 5] 9 | console.log(sort([14, 5, 10, 6, 3, 4, 21, 16, 9])); // prints [ 3, 4, 5, 6, 9, 10, 14, 16, 21 ] 10 | */ 11 | 12 | function sort(nums) { 13 | //!!START 14 | if (nums.length <= 1) { 15 | return nums; 16 | } 17 | let index = 0; 18 | let lowest = nums[0]; 19 | for (let i = 1; i < nums.length; i++) { 20 | if (nums[i] < lowest) { 21 | index = i; 22 | lowest = nums[i]; 23 | } 24 | } 25 | const firstPart = nums.splice(index, 1); 26 | return firstPart.concat(sort(nums)); 27 | //!!END 28 | } 29 | 30 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 31 | try { 32 | module.exports = sort; 33 | } catch (e) { 34 | module.exports = null; 35 | } -------------------------------------------------------------------------------- /w3/d5/solutions/bonus-practices/additional-practice/problems/03-even-number-range.js: -------------------------------------------------------------------------------- 1 | /* Even Number Range 2 | 3 | Write a function that accepts two numbers. 4 | The function should return an array of all even numbers between the two arguments inclusively. 5 | 6 | console.log(evenNumberRange(-3, 2)); // prints [-2, 0, 2] 7 | console.log(evenNumberRange(22, 25)); // prints [22, 24] 8 | console.log(evenNumberRange(2, 0)); // prints [] 9 | */ 10 | 11 | function evenNumberRange(num1, num2) { 12 | //!!START 13 | const result = []; 14 | for (let i = num1; i <= num2; i++) { 15 | if (i % 2 === 0) { 16 | result.push(i); 17 | } 18 | } 19 | return result; 20 | //!!END 21 | } 22 | 23 | /**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/ 24 | try { 25 | module.exports = evenNumberRange; 26 | } catch (e) { 27 | module.exports = null; 28 | } -------------------------------------------------------------------------------- /w3/d5/solutions/bonus-practices/additional-practice/test/02-recursive-sort-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | const sort = require('../problems/02-recursive-sort.js'); 3 | 4 | describe('sort()', () => { 5 | it('should return an array', () => { 6 | assert.strictEqual(Array.isArray(sort([3, 2, 1])), true); 7 | }); 8 | 9 | it('should sort the contents of an array from smallest to largest', () => { 10 | assert.deepEqual(sort([9]), [9]); 11 | assert.deepEqual(sort([3, 2, 1]), [1, 2, 3]); 12 | assert.deepEqual(sort([5, 4, 3, 2, 1]), [1, 2, 3, 4, 5]); 13 | assert.deepEqual( 14 | sort([14, 5, 10, 6, 3, 4, 21, 16, 9]), 15 | [3, 4, 5, 6, 9, 10, 14, 16, 21] 16 | ); 17 | }); 18 | 19 | it('should return an empty array if passed an empty array', () => { 20 | assert.deepEqual(sort([]), []); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /w3/d5/solutions/bonus-practices/additional-practice/test/03-even-number-range-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require("assert"); 2 | const evenNumberRange = require("../problems/03-even-number-range.js"); 3 | 4 | describe("evenNumberRange()", function() { 5 | it("should return an array", function() { 6 | assert.strictEqual(Array.isArray(evenNumberRange(-3, 2)), true); 7 | }); 8 | 9 | it("containing all even numbers between the two arguments inclusively", function() { 10 | assert.deepEqual(evenNumberRange(-3, 2), [-2, 0, 2]); 11 | assert.deepEqual(evenNumberRange(22, 25), [22, 24]); 12 | assert.deepEqual(evenNumberRange(2, 2), [2]); 13 | }); 14 | 15 | it ("should return an empty array if the first argument is greater than the second", function() { 16 | assert.deepEqual(evenNumberRange(3, 2), []); 17 | assert.deepEqual(evenNumberRange(1, -1), []); 18 | 19 | }); 20 | }) -------------------------------------------------------------------------------- /w3/d5/solutions/bonus-practices/additional-practice/test/04-dynamic-slice-spec.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | const dynamicSlice = require('../problems/04-dynamic-slice.js'); 3 | 4 | describe('dynamicSlice()', () => { 5 | it('should return a function', () => { 6 | const slicer = dynamicSlice(2, 4); 7 | assert.equal(slicer instanceof Function, true); 8 | }); 9 | 10 | it('the returned function should return a copy of the correct portion of the original array', () => { 11 | const slicer = dynamicSlice(1, 3); 12 | assert.deepEqual(slicer([0, 1, 2, 3]), [1, 2]); 13 | 14 | const slicer2 = dynamicSlice(2, 5); 15 | assert.deepEqual(slicer2([2, 'hello', false, 11, 'goodbye']), [false, 11, 'goodbye']); 16 | 17 | }); 18 | 19 | it('should exclude indices not available to the array', () => { 20 | const slicer = dynamicSlice(2, 7); 21 | assert.deepEqual(slicer([0, 1, 2, 3]), [2, 3]); 22 | assert.deepEqual(slicer(['kittens', 'puppies', 'cats', 'dogs']), ['cats', 'dogs']); 23 | 24 | const slicer2 = dynamicSlice(-10, 2); 25 | assert.deepEqual(slicer2([99, 40, 131, 8]), [99, 40]); 26 | }); 27 | }); 28 | --------------------------------------------------------------------------------