Sort until we can't sort anymore
This commit is contained in:
37
dist/scorm-again.js
vendored
37
dist/scorm-again.js
vendored
File diff suppressed because one or more lines are too long
2
dist/scorm-again.js.map
vendored
2
dist/scorm-again.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/scorm-again.min.js
vendored
2
dist/scorm-again.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -889,15 +889,16 @@ export default class BaseAPI {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int_pattern = /^(cmi\.interactions\.)(\d+)\.(.*)$/;
|
/**
|
||||||
const obj_pattern = /^(cmi\.objectives\.)(\d+)\.(.*)$/;
|
* Function to sort the array, which we'll call until we're done.
|
||||||
|
*
|
||||||
const result = Object.keys(json).map(function(key) {
|
* @param {string} a
|
||||||
return [String(key), json[key]];
|
* @param {string} b
|
||||||
});
|
* @param {string} c
|
||||||
|
* @param {string} d
|
||||||
// CMI interactions need to have id and type loaded before any other fields
|
* @return {number}
|
||||||
result.sort(function([a, b], [c, d]) {
|
*/
|
||||||
|
function resultSort([a, b], [c, d]) {
|
||||||
let test;
|
let test;
|
||||||
if ((test = testPattern(a, c, int_pattern)) !== null) {
|
if ((test = testPattern(a, c, int_pattern)) !== null) {
|
||||||
return test;
|
return test;
|
||||||
@@ -913,10 +914,25 @@ export default class BaseAPI {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int_pattern = /^(cmi\.interactions\.)(\d+)\.(.*)$/;
|
||||||
|
const obj_pattern = /^(cmi\.objectives\.)(\d+)\.(.*)$/;
|
||||||
|
|
||||||
|
const result = Object.keys(json).map(function(key) {
|
||||||
|
return [String(key), json[key]];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// CMI interactions need to have id and type loaded before any other fields
|
||||||
|
// Call the sort until everything is properly sorted.
|
||||||
|
// I must be missing an edge case in my sort?
|
||||||
|
let sorted_result = [];
|
||||||
|
while (sorted_result !== result.sort(resultSort)) {
|
||||||
|
sorted_result = result;
|
||||||
|
}
|
||||||
|
|
||||||
let obj;
|
let obj;
|
||||||
result.forEach((element) => {
|
sorted_result.forEach((element) => {
|
||||||
obj = {};
|
obj = {};
|
||||||
obj[element[0]] = element[1];
|
obj[element[0]] = element[1];
|
||||||
this.loadFromJSON(unflatten(obj), CMIElement);
|
this.loadFromJSON(unflatten(obj), CMIElement);
|
||||||
|
|||||||
Reference in New Issue
Block a user