Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rex Dri
Rex Dri
Commits
d6cd8f9c
Unverified
Commit
d6cd8f9c
authored
May 17, 2020
by
Estelle Veisemburger
Committed by
Florent Chehab
May 24, 2020
Browse files
feat(majorMinorMappings): add functions to get all the majors/minors corresponding to a major/minor
parent
0edd35e5
Changes
1
Hide whitespace changes
Inline
Side-by-side
frontend/src/utils/majorMinorMappings.js
View file @
d6cd8f9c
/**
* Mappings for updating majors
* DUMMIES are for tests
* @type {Object.<String, String>}
*/
export
const
majorMapping
=
{
GSM
:
"
IM
"
,
GM
:
"
IM
"
,
GSU
:
"
GU
"
GSU
:
"
GU
"
,
_DUMMY_MAJOR_1
:
"
_DUMMY_MAJOR_1
"
,
};
export
const
minorMapping
=
{};
/**
* Mapping for updating minors
* DUMMIES are for tests
* @type {Object.<String, Object.<String,String>>}
*/
export
const
minorMapping
=
{
_DUMMY_MAJOR_1
:
{
_DUMMY_MINOR_1
:
"
_DUMMY_MINOR_2
"
,
},
};
/**
* Returns the updated major
* @param {String} major
* @returns {String}
*/
export
function
getUpdatedMajor
(
major
)
{
if
(
major
in
majorMapping
)
{
return
majorMapping
[
major
];
...
...
@@ -13,9 +33,84 @@ export function getUpdatedMajor(major) {
return
major
;
}
/**
* Returns the updated minor
* @param {String} major
* @param {String} minor
* @returns {String}
*/
export
function
getUpdatedMinor
(
major
,
minor
)
{
if
(
major
in
minorMapping
&&
minor
in
minorMapping
[
major
])
{
return
minorMapping
[
major
][
minor
];
}
return
minor
;
}
/**
* Returns all the majors that correspond to a major
* @param {String} major
* @returns {Array.<String>}
*/
export
function
getAllMajors
(
major
)
{
const
out
=
new
Set
();
out
.
add
(
major
);
Object
.
entries
(
majorMapping
)
.
filter
(([,
newMajor
])
=>
newMajor
===
major
)
.
forEach
(([
oldMajor
])
=>
{
out
.
add
(
oldMajor
);
});
return
[...
out
];
}
/**
* Returns all the minors that correspond to a minor
* @returns {Array.<String>}
*/
export
function
getAllMinors
(
major
,
minor
)
{
const
out
=
new
Set
();
out
.
add
(
minor
);
const
allMajors
=
getAllMajors
(
major
);
allMajors
.
forEach
((
el
)
=>
Object
.
entries
(
minorMapping
)
.
filter
(([
maj
])
=>
maj
===
el
)
.
forEach
(([,
minors
])
=>
{
Object
.
entries
(
minors
)
.
filter
(([,
newMinor
])
=>
newMinor
===
minor
)
.
forEach
(([
oldMinor
])
=>
{
out
.
add
(
oldMinor
);
});
})
);
return
[...
out
];
}
/**
* Returns the updated data from univMajorMinors endpoint
*
* @param {Array.<{major: string, minors: Array.<String>}>} univMajorMinors
* @returns {Array.<{major: string, minors: Array.<String>}>}
*/
export
function
getUpdatedUnivMajorMinors
(
univMajorMinors
)
{
/**
* @type {Map<string, Set.<string>>}
*/
const
agg
=
new
Map
();
univMajorMinors
.
forEach
((
el
)
=>
{
const
newMajor
=
getUpdatedMajor
(
el
.
major
);
const
newMinors
=
el
.
minors
.
map
((
min
)
=>
getUpdatedMinor
(
el
.
major
,
min
));
if
(
!
agg
.
has
(
newMajor
))
agg
.
set
(
newMajor
,
new
Set
(
newMinors
));
const
aggMajor
=
agg
.
get
(
newMajor
);
newMinors
.
forEach
((
m
)
=>
{
aggMajor
.
add
(
m
);
});
});
return
[...
agg
.
entries
()].
map
(([
major
,
minorsSet
])
=>
({
major
,
minors
:
[...
minorsSet
],
}));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment