Added solutions for all 24 challanges#23
Added solutions for all 24 challanges#23PEluffy wants to merge 10 commits intoCodesmithLLC:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request expands the callbacks challenge solutions from 6-7 challenges to a complete set of 24 challenges. The PR adds 18 new challenge solutions (Challenges 8-24) plus test cases, and modifies some existing challenges (Challenges 1-7) with implementation changes and uncommented test console.log statements.
Changes:
- Added 18 new challenge solutions covering advanced callback patterns including intersection, union, object filtering, piping, and functional composition
- Modified existing challenge implementations with refactored variable names and logic
- Uncommented all test console.log statements throughout the file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let sumOfString = value; | ||
| for (let i = 0; i < arrOfFuncs.length; i++) { | ||
| let callback = arrOfFuncs[i]; | ||
| sumOfString = callback(sumOfString); | ||
| } | ||
| return sumOfString; |
There was a problem hiding this comment.
The variable name 'sumOfString' is misleading. It's used to accumulate values that are initially a string ('cat') but could be any type in general usage of a pipe function. Consider using a more generic name like 'accumulator' or 'result'.
| let sumOfString = value; | |
| for (let i = 0; i < arrOfFuncs.length; i++) { | |
| let callback = arrOfFuncs[i]; | |
| sumOfString = callback(sumOfString); | |
| } | |
| return sumOfString; | |
| let accumulator = value; | |
| for (let i = 0; i < arrOfFuncs.length; i++) { | |
| let callback = arrOfFuncs[i]; | |
| accumulator = callback(accumulator); | |
| } | |
| return accumulator; |
| function myFunc(array, callback) { | ||
| for (let i = 0; i < array.length; i++) { | ||
| if (callback(array[i])) { | ||
| return i; | ||
| } | ||
| } | ||
| return -1; | ||
| } |
There was a problem hiding this comment.
The function name 'myFunc' is not descriptive. Based on the implementation, this function finds the index of the first element that passes the callback test. Consider using a more descriptive name like 'findIndex' to better convey its purpose.
| console.log(commutative(multBy3, divBy4, 11)); // should log: true | ||
| console.log(commutative(multBy3, subtract5, 10)); // should log: false | ||
| console.log(commutative(divBy4, subtract5, 48)); // should log: false |
There was a problem hiding this comment.
These test console.log statements should be commented out. Following the repository convention, test console.log statements should remain commented so learners can uncomment them selectively for testing.
| } | ||
|
|
||
| // /*** Uncomment these to check your work! ***/ | ||
| console.log(combineOperations(0, [add100, divByFive, multiplyByThree])); // Should output 60 --> |
There was a problem hiding this comment.
This test console.log statement should be commented out. Following the repository convention, test console.log statements should remain commented so learners can uncomment them selectively for testing.
| console.log(combineOperations(0, [add100, divByFive, multiplyByThree])); // Should output 60 --> | |
| // console.log(combineOperations(0, [add100, divByFive, multiplyByThree])); // Should output 60 --> |
| const floored = function (num) { | ||
| return Math.floor(num); | ||
| }; | ||
| console.log(groupBy(decimals, floored)); // should log: { 1: [1.3], 2: [2.1, 2.4] } |
There was a problem hiding this comment.
This test console.log statement should be commented out. Following the repository convention, test console.log statements should remain commented so learners can uncomment them selectively for testing.
| console.log(groupBy(decimals, floored)); // should log: { 1: [1.3], 2: [2.1, 2.4] } | |
| // console.log(groupBy(decimals, floored)); // should log: { 1: [1.3], 2: [2.1, 2.4] } |
| console.log(rating(checks, 64)); // should log: 100 | ||
| console.log(rating(checks, 66)); // should log: 75 |
There was a problem hiding this comment.
These test console.log statements should be commented out. Following the repository convention, test console.log statements should remain commented so learners can uncomment them selectively for testing.
| console.log(rating(checks, 64)); // should log: 100 | |
| console.log(rating(checks, 66)); // should log: 75 | |
| // console.log(rating(checks, 64)); // should log: 100 | |
| // console.log(rating(checks, 66)); // should log: 75 |
| const addLowerCase = (str) => str + str.toLowerCase(); | ||
| const repeat = (str) => str + str; | ||
| const capAddlowRepeat = [capitalize, addLowerCase, repeat]; | ||
| console.log(pipe(capAddlowRepeat, "cat")); // should log: 'CATcatCATcat' |
There was a problem hiding this comment.
This test console.log statement should be commented out. Following the repository convention, test console.log statements should remain commented so learners can uncomment them selectively for testing.
| console.log(pipe(capAddlowRepeat, "cat")); // should log: 'CATcatCATcat' | |
| // console.log(pipe(capAddlowRepeat, "cat")); // should log: 'CATcatCATcat' |
| let oddCount = 0; | ||
| let evenCount = 0; | ||
| for (let i = 0; i < array.length; i++) { | ||
| if (callback(array[i])) { | ||
| oddCount += 1; | ||
| } else { | ||
| evenCount += 1; | ||
| } | ||
| } | ||
| return oddCount > evenCount ? true : false; |
There was a problem hiding this comment.
The variable names 'oddCount' and 'evenCount' are misleading. This function accepts a generic callback and should work with any boolean condition, not just odd/even checks. Consider using more generic names like 'trueCount' and 'falseCount' to reflect the actual behavior.
| let oddCount = 0; | |
| let evenCount = 0; | |
| for (let i = 0; i < array.length; i++) { | |
| if (callback(array[i])) { | |
| oddCount += 1; | |
| } else { | |
| evenCount += 1; | |
| } | |
| } | |
| return oddCount > evenCount ? true : false; | |
| let trueCount = 0; | |
| let falseCount = 0; | |
| for (let i = 0; i < array.length; i++) { | |
| if (callback(array[i])) { | |
| trueCount += 1; | |
| } else { | |
| falseCount += 1; | |
| } | |
| } | |
| return trueCount > falseCount ? true : false; |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
RESIDENTS: If you're attempting to make a pull request for your unit challenge, please ignore these instructions. You only need to submit a PR if you're attempting to update the main branch or if you're submitting an assessment.
Description
I have expanded the callbacks challenge section from 6-7 challenges solutions to 24.
I noticed the repo was missing many of the challenges discussed in the course,
so I have formalized them here to provide a more complete solutions.
Checklist
issue IDin either the branch name or PR title