很抱歉,如果我的标题真的有误导性,我仍然不知道如何称呼我的问题,
所以我有一套阵列
0: {name: "Bob", time_in: "18:00:00", event_start: "19:00:00", attendance_status: "yes"}
1: {name: "Dino", time_in: "19:05:00", event_start: "19:00:00", attendance_status: "yes"}
2: {name: "Anna", time_in: "19:05:00", event_start: "19:00:00", attendance_status: "no"}
3: {name: "Tina", time_in: "19:00:00", event_start: "19:00:00", attendance_status: "N/A"}
4: {name: "Aiza", time_in: "18:00:00", event_start: "19:00:00", attendance_status: "N/A"}
length: 4
__proto__: Array(0)
如果鲍勃的时间早在活动开始之前,我怎么能让他达到10分呢。
所以它会像这个
0: {name: "Bob", time_in: "18:00:00", event_start: "19:00:00", attendance_status: "yes"}
1: {name: "Bob", time_in: "18:00:00", event_start: "19:00:00", attendance_status: "yes"}
2: {name: "Bob", time_in: "18:00:00", event_start: "19:00:00", attendance_status: "yes"}
3: {name: "Bob", time_in: "18:00:00", event_start: "19:00:00", attendance_status: "yes"}
4: {name: "Bob", time_in: "18:00:00", event_start: "19:00:00", attendance_status: "yes"}
5: {name: "Bob", time_in: "18:00:00", event_start: "19:00:00", attendance_status: "yes"}
6: {name: "Bob", time_in: "18:00:00", event_start: "19:00:00", attendance_status: "yes"}
7: {name: "Bob", time_in: "18:00:00", event_start: "19:00:00", attendance_status: "yes"}
8: {name: "Bob", time_in: "18:00:00", event_start: "19:00:00", attendance_status: "yes"}
9: {name: "Bob", time_in: "18:00:00", event_start: "19:00:00", attendance_status: "yes"}
10: {name: "Dino", time_in: "19:05:00", event_start: "19:00:00", attendance_status: "yes"}
11: {name: "Anna", time_in: "19:05:00", event_start: "19:00:00", attendance_status: "no"}
12: {name: "Tina", time_in: "19:00:00", event_start: "19:00:00", attendance_status: "N/A"}
13: {name: "Aiza", time_in: "18:00:00", event_start: "19:00:00", attendance_status: "N/A"}
他们的输入将取决于他们的time_in和event_start
这是的其他规则
TIME_IN TIME_START attendance_ status
6:00 7:00 yes = 10 tickets (EARLY + YES)
7:05 7:00 yes = 5 tickets (LATE + YES)
7:05 7:00 no = 3 tickets (LATE OR EARLY + NO)
7:00 7:00 N/A = 1 tickets (LATE + N/A)
6:00 7:00 N/A = 1 tickets(EARLY + N/A)
我正在尝试用javascript实现这一点,但我仍然不知道如何使索引为多个。任何帮助都将不胜感激。
您使用的是一个对象数组。要访问其中任何一个,您可以执行以下操作。
// CHANGE THE ARRAY NUMBER TO ANY IN THE ARRAY YOU WANT TO ACCESS
array[0].time_in; // OR
array[0].name;
然后通过推断,我们可以。。。
// DECLARE YOUR ARRAY, AND ANOTHER HOLDING ARRAY
var people = // YOUR ARRAY HERE
var holding = [];
// MAKE A LOOP FOR THE ARRAY
people.forEach(function(item){
// CREATE AN IF LOOP TO CHECK YOUR CONDITION
if(item.time_in < item.event_start) {
for(var i = 0; i <10; i++) {
holding.push(item);
}
} else {
holding.push(item);
}
});
// PLACE OVERWRITE THE FIRST ARRAY WITH YOUR HOLDING
people = holding;
那么,你的家庭作业就是尝试将你的"规则"应用到这个逻辑中。