Skip to content

Commit f92cef5

Browse files
committed
refactor inheritance principle implementation
1 parent 685d420 commit f92cef5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

validators/nii.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,21 +315,23 @@ function potentialLocations(path) {
315315
});
316316

317317
if (ses) {
318-
var sessionLevelPath= "/" + sub + "/" + ses + "/" + sessionLevelComponentList.join("_");
319-
potentialPaths.push(sessionLevelPath);
318+
addPotentialPaths(sessionLevelComponentList, potentialPaths, 2, "/" + sub + "/" + ses + "/");
320319
}
321-
322-
var subjectLevelPath = "/" + sub + "/" + subjectLevelComponentList.join("_");
323-
potentialPaths.push(subjectLevelPath);
324-
325-
var topLevelPath = "/" + topLevelComponentList.join("_");
326-
potentialPaths.push(topLevelPath);
327-
320+
addPotentialPaths(subjectLevelComponentList, potentialPaths, 1, "/" + sub + "/");
321+
addPotentialPaths(topLevelComponentList, potentialPaths, 0, "/");
328322
potentialPaths.reverse();
329323

330324
return potentialPaths;
331325
}
332326

327+
function addPotentialPaths(componentList, potentialPaths, offset, prefix) {
328+
for (var i = componentList.length; i > offset; i--) {
329+
var tmpList = componentList.slice(0, i-1).concat([componentList[componentList.length-1]]);
330+
var sessionLevelPath = prefix + tmpList.join("_");
331+
potentialPaths.push(sessionLevelPath);
332+
}
333+
}
334+
333335
/**
334336
* Generate Merged Sidecar Dictionary
335337
*

0 commit comments

Comments
 (0)