我正在制作一个待办事项应用程序,我想了一些方法来增加它的趣味性,所以我实现了一个项目进度功能。因此,在应用程序中,您可以创建 projects
,每个项目可以有 todolists
,每个待办事项可以有 todos
。
所以当用户切换待办事项时,我会以这种方式重新计算项目的进度
const todoContirubutioToProjectPorgess=1/projectTodosTotalCount
project.progress += todoContirubutioToProjectPorgess
如果项目中的 todolists 有相同数量的 todos ,这工作正常,但如果它们不是,这并没有真正意义,例如,让我们考虑以下情况:
案例1
project : [
todoList1[todo1,todo2],
todoList2[todo3,todo4]
]
//todo1's contribution to project's progress is the same todo3's so it works here
案例 2
project : [
todoList1[todo1,todo2],
todoList2[todo3,todo4,todo5]
]
//todo1's contribution to project's progress is bigger than todo3 , since todo1 makes 50% of todoList1 and todo3 makes only 30% todoList2
我试过了
const todoListContirubutioToProjectPorgess = todoListTodosCount/projectTodosTotalCount
const todoContirubutioToPorgess = 1/todoListContirubutioToProjectPorgess
project.progress += todoContirubutioToPorgess
但它没有按我的预期工作,您对此有何看法以及您将如何处理
答案 0 :(得分:1)
设 x
个待办事项列表,任务数量为 [t1, t2, t3, ...tx]
个。
每个待办事项列表的贡献 = 100/x %
列表 1 中每一项的贡献 = (100/x) / t1%
= 100/(x*t1) %
.
列表 2 中每一项的贡献 = (100/x) / t2%
= 100/(x*t2) %
.
列表 x 中每一项的贡献 = (100/x) / tx%
= 100/(x*tx) %
。
对于每个任务,您只需要两个变量:列表总数和当前列表中的任务数。然后用上面的公式得到进度增量。