Skip to content

Added solutions for all 24 challanges#23

Open
PEluffy wants to merge 10 commits intoCodesmithLLC:masterfrom
PEluffy:solutions-for-callbacks
Open

Added solutions for all 24 challanges#23
PEluffy wants to merge 10 commits intoCodesmithLLC:masterfrom
PEluffy:solutions-for-callbacks

Conversation

@PEluffy
Copy link

@PEluffy PEluffy commented Feb 20, 2026

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

  • I've added a descriptive title to this PR
  • I've referenced an issue in Linear through including the issue ID in either the branch name or PR title
  • I've tagged Marselena Sequoia as a reviewer

Copilot AI review requested due to automatic review settings February 20, 2026 22:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +374 to +379
let sumOfString = value;
for (let i = 0; i < arrOfFuncs.length; i++) {
let callback = arrOfFuncs[i];
sumOfString = callback(sumOfString);
}
return sumOfString;
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'.

Suggested change
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;

Copilot uses AI. Check for mistakes.
Comment on lines +440 to +447
function myFunc(array, callback) {
for (let i = 0; i < array.length; i++) {
if (callback(array[i])) {
return i;
}
}
return -1;
}
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +327 to +329
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
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
}

// /*** Uncomment these to check your work! ***/
console.log(combineOperations(0, [add100, divByFive, multiplyByThree])); // Should output 60 -->
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
console.log(combineOperations(0, [add100, divByFive, multiplyByThree])); // Should output 60 -->
// console.log(combineOperations(0, [add100, divByFive, multiplyByThree])); // Should output 60 -->

Copilot uses AI. Check for mistakes.
const floored = function (num) {
return Math.floor(num);
};
console.log(groupBy(decimals, floored)); // should log: { 1: [1.3], 2: [2.1, 2.4] }
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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] }

Copilot uses AI. Check for mistakes.
Comment on lines +369 to +370
console.log(rating(checks, 64)); // should log: 100
console.log(rating(checks, 66)); // should log: 75
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
const addLowerCase = (str) => str + str.toLowerCase();
const repeat = (str) => str + str;
const capAddlowRepeat = [capitalize, addLowerCase, repeat];
console.log(pipe(capAddlowRepeat, "cat")); // should log: 'CATcatCATcat'
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
console.log(pipe(capAddlowRepeat, "cat")); // should log: 'CATcatCATcat'
// console.log(pipe(capAddlowRepeat, "cat")); // should log: 'CATcatCATcat'

Copilot uses AI. Check for mistakes.
Comment on lines +203 to +212
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;
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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;

Copilot uses AI. Check for mistakes.
PEluffy and others added 9 commits February 23, 2026 19:36
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants