refactor(js): use forEach and map instead of own function

This commit is contained in:
Philipp Matthias Schaefer 2021-03-14 21:43:39 +01:00
parent 9acb4eb28c
commit 4edbd90de8

View File

@ -67,15 +67,14 @@ function hideModal() {
FIELDS = ['username', 'old_password', 'new_password']
function mapFields(thunk) {
for (fieldIndex in FIELDS) {
const fieldName = FIELDS[fieldIndex]
thunk(document.querySelector(`input[name=${fieldName}]`))
}
function fields() {
return FIELDS.map(
fieldName => document.querySelector(`input[name=${fieldName}]`)
);
}
function clearFields() {
mapFields(field => {
fields().forEach(field => {
field.value = "";
});
}
@ -83,7 +82,7 @@ function clearFields() {
function changePasswords() {
const query = {};
mapFields(field => {
fields().forEach(field => {
query[field.name] = field.value;
});