Maaf jika judul saya benar-benar menyesatkan, saya masih tidak tahu bagaimana menyebut masalah saya,

Jadi saya punya satu set array

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)

Bagaimana saya bisa membuat bob menjadi x10 jika waktunya lebih awal sebelum acara dimulai.

Jadi akan seperti ini

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"}

Entri mereka akan bergantung pada time_in mereka dan event_start

Ini aturan lainnya

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)

Saya mencoba melakukan ini dalam javascript tetapi saya masih tidak tahu bagaimana saya bisa membuat indeks menjadi banyak. bantuan apa pun akan sangat dihargai.

0
Janessa Bautista 28 Oktober 2019, 12:16

1 menjawab

Jawaban Terbaik

Anda menggunakan array objek. Untuk mengakses salah satu dari mereka, Anda dapat melakukan hal berikut.

// CHANGE THE ARRAY NUMBER TO ANY IN THE ARRAY YOU WANT TO ACCESS
array[0].time_in; // OR
array[0].name;

Kemudian dengan mengekstrapolasi dari itu kita dapat...

// 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;

Pekerjaan rumah Anda kemudian adalah mencoba dan menerapkan 'aturan' Anda pada logika ini.

0
Shib 28 Oktober 2019, 09:44