refactor(js): use forEach and map instead of own function
This commit is contained in:
		| @@ -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; | ||||
|   }); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user