Skip to content

Commit

Permalink
Merge pull request #24 from CMU-17313Q/haya1
Browse files Browse the repository at this point in the history
Haya1- Adding my P1 file changes to the group's repo
This pull request includes my changes to the P1 file, specifically the refactored code from src/batch.js. The modifications aim to reduce the cognitive complexity of the code, improving its readability and maintainability.
  • Loading branch information
Hakaabi authored Sep 26, 2024
2 parents ca05bbb + 78e2a19 commit f164d55
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,23 @@ const DEFAULT_BATCH_SIZE = 100;

const sleep = util.promisify(setTimeout);

exports.processSortedSet = async function (setKey, process, options) {
options = options || {};
// I will reduce the complexity of the code by making helper functions outside the main function
// where the errors show

// helper functions:
// fixing error 1:
function processIsFunction(process) {
if (typeof process !== 'function') {
throw new Error('[[error:process-not-a-function]]');
}
}


exports.processSortedSet = async function (setKey, process, options) {
console.log('Hakaabi: Refactored code is running!');
options = options || {};

processIsFunction(process);

// Progress bar handling (upgrade scripts)
if (options.progress) {
Expand Down Expand Up @@ -68,6 +79,7 @@ exports.processSortedSet = async function (setKey, process, options) {
stop = start + options.batch - 1;
}
};
console.log('Hakaabi: Refactored code stopped running!');

exports.processArray = async function (array, process, options) {
options = options || {};
Expand Down

0 comments on commit f164d55

Please sign in to comment.