Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions challenges/determineCourseOrder/determineCourseOrder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// nextCourse= course we're checking
// currentCourse is example below
// ["Prereq", "NextLevelCourse"],
// ["Data Structures", "Algorithms"]
function determineIsPrereq(nextCourse, currentCourse) {
let isPrereq = false;
if (nextCourse === currentCourse[0]) {
isPrereq = true;
}
return isPrereq;
}

function determineCourseOrder(courseList) {
const finalCourseList = [courseList[0][0]];

for (let i = 0; i < courseList.length; i++) {
// insert forwards or backwards base on prereq
for (let j = 0; j < finalCourseList.length; j++) {
if (determineIsPrereq(courseList[i], finalCourseList[j])) {
finalCourseList.splice(j, 0, courseList[i]);
break;
} else {
finalCourseList.splice(j + 1, 0, courseList[i]);
break;
}
}
}
console.log(finalCourseList);
return finalCourseList;
}

/* works */
function findHalfwayCourse(finalCourseList) {
const halfway = (finalCourseList.length) / 2;
const halfwayIndex = Math.floor(halfway);
const halfwayCourse = finalCourseList[halfwayIndex];
return halfwayCourse;
}


function finalFunction(courses) {
const finalCourseList = determineCourseOrder(courses);

let finalCourse = '';
finalCourse = findHalfwayCourse(finalCourseList);

return finalCourse;
}

module.exports = {
determineIsPrereq, determineCourseOrder, findHalfwayCourse, finalFunction,
};
92 changes: 92 additions & 0 deletions challenges/determineCourseOrder/determineCourseOrder.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const {
isPrereq, determineCourseOrder, findHalfwayCourse, finalFunction,
} = require('./determineCourseOrder');

describe('determineCourseOrder Test', () => {
test('testOne', () => {
const testCase1 = {
input: [
['Data Structures', 'Algorithms'],
['Foundations of Computer Science', 'Operating Systems'],
['Computer Networks', 'Computer Architecture'],
['Algorithms', 'Foundations of Computer Science'],
['Computer Architecture', 'Data Structures'],
['Software Design', 'Computer Networks'],
],
order: ['Software Design',
'Computer Networks',
'Computer Architecture',
'Data Structures',
'Algorithms',
'Foundations of Computer Science',
'Operating Systems',
],
output: 'Data Structures',
};
const result = determineCourseOrder(testCase1.input);
expect(result).toEqual(testCase1.output);
});

test('testOne', () => {
const testCase2 = {
input: [
['Data Structures', 'Algorithms'],
['Algorithms', 'Foundations of Computer Science'],
['Foundations of Computer Science', 'Logic'],
],
output: 'Algorithms',
};
const result = determineCourseOrder(testCase2.input);
expect(result).toEqual(testCase2.output);
});

test('testOne', () => {
const testCase3 = {
input: [
['Data Structures', 'Algorithms'],
],
output: 'Data Structures',
};
const result = determineCourseOrder(testCase3.input);
expect(result).toEqual(testCase3.output);
});
});

describe('isPrereq Test', () => {
test('testOne', () => {
const testCase3 = {
input: [
['Data Structures', 'Algorithms'],
],
output: 'Data Structures',
};
const result = isPrereq(testCase3.input);
expect(result).toEqual(testCase3.output);
});
});

describe('findHalfwayCourse Test', () => {
test('testOne', () => {
const testCase3 = {
input: [
['Data Structures', 'Algorithms'],
],
output: 'Data Structures',
};
const result = findHalfwayCourse(testCase3.input);
expect(result).toEqual(testCase3.output);
});
});

describe('finalFunction Test', () => {
test('testOne', () => {
const testCase3 = {
input: [
['Data Structures', 'Algorithms'],
],
output: 'Data Structures',
};
const result = finalFunction(testCase3.input);
expect(result).toEqual(testCase3.output);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
determineCourseOrder Notes go here!
53 changes: 53 additions & 0 deletions challenges/determineCourseOrder/determineCourseOrderSpec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
determineCourseOrder Spec goes here!

/*
You're developing a system for scheduling advising meetings with students in a Computer Science program. Each meeting should be scheduled when a student has completed 50% of their academic program.

Each course at our university has at most one prerequisite that must be taken first. No two courses share a prerequisite. There is only one path through the program.

Write a function that takes a list of (prerequisite, course) pairs, and returns the name of the course that the student will be taking when they are halfway through their program. (If a track has an even number of courses, and therefore has two "middle" courses, you should return the first one.)

Sample input 1: (arbitrarily ordered)
prereqs_courses1 = [
["Data Structures", "Algorithms"],
["Foundations of Computer Science", "Operating Systems"],
["Computer Networks", "Computer Architecture"],
["Algorithms", "Foundations of Computer Science"],
["Computer Architecture", "Data Structures"],
["Software Design", "Computer Networks"]
]

//my notes ["PREREQ","NEXTREQ"]

In this case, the order of the courses in the program is:
Software Design
Computer Networks
Computer Architecture
Data Structures
Algorithms
Foundations of Computer Science
Operating Systems

Sample output 1:
"Data Structures"


Sample input 2:
prereqs_courses2 = [
["Data Structures", "Algorithms"],
["Algorithms", "Foundations of Computer Science"],
["Foundations of Computer Science", "Logic"]
]


Sample output 2:
"Algorithms"
Sample input 3:
prereqs_courses3 = [
["Data Structures", "Algorithms"],
]


Sample output 3:
"Data Structures"
*/
2 changes: 1 addition & 1 deletion helpers/generateBoilerPlate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const fs = require('fs');
// TODO: split up challenges
// TODO: add appDesignSection?
// ////SETUP HERE//////
const solutionName = 'findArrayIntersect';
const solutionName = 'determineCourseOrder';
// TODO: look into setting up map or enum for this
/* challenge || dataStructure || algorithm || designPattern || concept */
const codeChallengeType = 'challenge';
Expand Down