Last active
November 3, 2016 11:51
-
-
Save Lxxyx/8ff943887dffba2702462eaea1effce7 to your computer and use it in GitHub Desktop.
SortSchedule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sortWeek (schedules) { | |
| schedules = schedules.map(s => sortDay(s)) | |
| } | |
| function sortDay (schedule) { | |
| const sorted = [] | |
| const hasSort = [] | |
| let base = schedule[0] | |
| for (let i = 0; i < schedule.length; i++) { | |
| if (base === null) { | |
| hasSort.push(true) | |
| sorted.push({ | |
| time: [i], | |
| lesson: null | |
| }) | |
| if (hasNext(schedule, i)) { | |
| base = schedule[i+1] | |
| continue | |
| } | |
| continue | |
| } | |
| if (hasSort[i] === true) { | |
| continue | |
| } | |
| const lesson = { | |
| time: [i], | |
| lesson: schedule[i] | |
| } | |
| let next = i | |
| while (hasNext(schedule, next) && isSame(base, schedule[next + 1])) { | |
| next += 1 | |
| lesson.time.push(next) | |
| hasSort.push(true) | |
| } | |
| hasSort.push(true) | |
| sorted.push(lesson) | |
| base = schedule[next + 1] | |
| } | |
| console.log(sorted) | |
| } | |
| function hasNext (arr, $index) { | |
| if (arr[$index + 1] !== undefined) { | |
| return true | |
| } | |
| return false | |
| } | |
| function isSame (curr, next) { | |
| const { jxdd, jsmcmx, wxskbjmcmx, kcmc } = curr | |
| if (next === null) { | |
| return false | |
| } | |
| if (next.jxdd === jxdd && next.jsmcmx === jsmcmx && next.wxskbjmcmx === wxskbjmcmx && next.kcmc === kcmc) { | |
| return true | |
| } | |
| return false | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment