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