From f0d65e5f577001369b781c425218ac42788a682b Mon Sep 17 00:00:00 2001 From: hieu-w Date: Mon, 2 Sep 2024 23:33:06 +0700 Subject: [PATCH] Vue demo: Refactoring foreach to reduce. --- examples/vue-example/src/App.vue | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/vue-example/src/App.vue b/examples/vue-example/src/App.vue index d25e282e..4446f81a 100644 --- a/examples/vue-example/src/App.vue +++ b/examples/vue-example/src/App.vue @@ -626,12 +626,16 @@ const allMFAFactors = Object.values(MFA_FACTOR); const mfaSettings = computed(() => { if (!selectedMFAFactors.value?.length) return {}; - const mfaSettings: Record = {}; - allMFAFactors.forEach((factor) => { - mfaSettings[factor] = { enable: selectedMFAFactors.value.includes(factor), mandatory: selectedMandatoryMFAFactors.value.includes(factor) }; - }); - console.log("mfaSettings", mfaSettings); - return mfaSettings; + const newMfaSettings = allMFAFactors.reduce( + (acc, factor) => { + acc[factor] = { enable: selectedMFAFactors.value.includes(factor), mandatory: selectedMandatoryMFAFactors.value.includes(factor) }; + return acc; + }, + {} as Record + ); + + console.log("newMfaSettings", newMfaSettings); + return newMfaSettings; }); const isValidForm = computed(() => {