NEWS
Zeiten filtern Array
-
Könnt ihr mir bitte nochmal helfen.
ich habe hier ein sortiertes Array, sortiert nach höchsten Preis zwischen aktueller Uhrzeit und Sonnenaufgang.
Jetzt würde ich gerne den höchsten Preis in diesem Zeitraum ausgeben, aber ohne Zeiten. Das ganze soll eine einfache Variabel sein, die den Preis beinhaltet.wie kann ich das bewerkstelligen?
Ich denke eine for Scheife ist hier sinnvoll[ [ 0.3781, '17:00', '17:30' ], [ 0.3781, '17:30', '18:00' ], [ 0.375, '18:00', '18:30' ], [ 0.375, '18:30', '19:00' ], [ 0.3569, '19:00', '19:30' ], [ 0.3569, '19:30', '20:00' ], [ 0.3488, '16:00', '16:30' ], [ 0.3488, '16:30', '17:00' ], [ 0.3422, '20:00', '20:30' ], [ 0.3422, '20:30', '21:00' ], [ 0.3369, '22:00', '22:30' ], [ 0.3369, '22:30', '23:00' ], [ 0.3349, '21:00', '21:30' ], [ 0.3349, '21:30', '22:00' ], [ 0.3343, '15:00', '15:30' ], [ 0.3343, '15:30', '16:00' ], [ 0.3242, '23:00', '23:30' ], [ 0.3242, '23:30', '00:00' ], [ 0.3113, '00:00', '00:30' ], [ 0.3113, '00:30', '01:00' ], [ 0.3078, '06:00', '06:30' ], [ 0.3078, '06:30', '07:00' ], [ 0.3064, '07:00', '07:30' ], [ 0.3064, '07:30', '08:00' ], [ 0.3029, '05:00', '05:30' ], [ 0.3029, '05:30', '06:00' ], [ 0.302, '08:00', '08:30' ], [ 0.3016, '01:00', '01:30' ], [ 0.3016, '01:30', '02:00' ], [ 0.2995, '02:00', '02:30' ], [ 0.2995, '02:30', '02:00' ], [ 0.2961, '03:00', '03:30' ], [ 0.2961, '03:30', '04:00' ], [ 0.2954, '04:00', '04:30' ], [ 0.2954, '04:30', '05:00' ], [ 0.2782, '14:00', '14:30' ], [ 0.2782, '14:30', '15:00' ], [ 0.2667, '10:00', '10:30' ], [ 0.2667, '10:30', '11:00' ], [ 0.2522, '11:00', '11:30' ], [ 0.2522, '11:30', '12:00' ], [ 0.2492, '12:00', '12:30' ], [ 0.2492, '12:30', '13:00' ], [ 0.2492, '13:00', '13:30' ], [ 0.2492, '13:30', '14:00' ] ]
Danke und Grüße
-
@diamand2k22 sagte: sortiertes Array, sortiert nach höchsten Preis
Das Array ist nach Uhrzeit sortiert.
@diamand2k22 sagte in Zeiten filtern Array:
den höchsten Preis in diesem Zeitraum ausgeben
const arr = [ [ 0.3781, '17:00', '17:30' ], [ 0.3781, '17:30', '18:00' ], [ 0.375, '18:00', '18:30' ], [ 0.375, '18:30', '19:00' ], [ 0.3569, '19:00', '19:30' ], [ 0.3569, '19:30', '20:00' ], [ 0.3488, '16:00', '16:30' ], [ 0.3488, '16:30', '17:00' ], [ 0.3422, '20:00', '20:30' ], [ 0.3422, '20:30', '21:00' ], [ 0.3369, '22:00', '22:30' ], [ 0.3369, '22:30', '23:00' ], [ 0.3349, '21:00', '21:30' ], [ 0.3349, '21:30', '22:00' ], [ 0.3343, '15:00', '15:30' ], [ 0.3343, '15:30', '16:00' ], [ 0.3242, '23:00', '23:30' ], [ 0.3242, '23:30', '00:00' ], [ 0.3113, '00:00', '00:30' ], [ 0.3113, '00:30', '01:00' ], [ 0.3078, '06:00', '06:30' ], [ 0.3078, '06:30', '07:00' ], [ 0.3064, '07:00', '07:30' ], [ 0.3064, '07:30', '08:00' ], [ 0.3029, '05:00', '05:30' ], [ 0.3029, '05:30', '06:00' ], [ 0.302, '08:00', '08:30' ], [ 0.3016, '01:00', '01:30' ], [ 0.3016, '01:30', '02:00' ], [ 0.2995, '02:00', '02:30' ], [ 0.2995, '02:30', '02:00' ], [ 0.2961, '03:00', '03:30' ], [ 0.2961, '03:30', '04:00' ], [ 0.2954, '04:00', '04:30' ], [ 0.2954, '04:30', '05:00' ], [ 0.2782, '14:00', '14:30' ], [ 0.2782, '14:30', '15:00' ], [ 0.2667, '10:00', '10:30' ], [ 0.2667, '10:30', '11:00' ], [ 0.2522, '11:00', '11:30' ], [ 0.2522, '11:30', '12:00' ], [ 0.2492, '12:00', '12:30' ], [ 0.2492, '12:30', '13:00' ], [ 0.2492, '13:00', '13:30' ], [ 0.2492, '13:30', '14:00' ] ]; let max = 0; for(const ele of arr) { if(ele[0] > max) max = ele[0]; }; log(max);
-
-
@paul53 said in Zeiten filtern Array:
@diamand2k22 sagte: sortiertes Array, sortiert nach höchsten Preis
Das Array ist nach Uhrzeit sortiert.
@diamand2k22 sagte in Zeiten filtern Array:
den höchsten Preis in diesem Zeitraum ausgeben
const arr = [ [ 0.3781, '17:00', '17:30' ], [ 0.3781, '17:30', '18:00' ], [ 0.375, '18:00', '18:30' ], [ 0.375, '18:30', '19:00' ], [ 0.3569, '19:00', '19:30' ], [ 0.3569, '19:30', '20:00' ], [ 0.3488, '16:00', '16:30' ], [ 0.3488, '16:30', '17:00' ], [ 0.3422, '20:00', '20:30' ], [ 0.3422, '20:30', '21:00' ], [ 0.3369, '22:00', '22:30' ], [ 0.3369, '22:30', '23:00' ], [ 0.3349, '21:00', '21:30' ], [ 0.3349, '21:30', '22:00' ], [ 0.3343, '15:00', '15:30' ], [ 0.3343, '15:30', '16:00' ], [ 0.3242, '23:00', '23:30' ], [ 0.3242, '23:30', '00:00' ], [ 0.3113, '00:00', '00:30' ], [ 0.3113, '00:30', '01:00' ], [ 0.3078, '06:00', '06:30' ], [ 0.3078, '06:30', '07:00' ], [ 0.3064, '07:00', '07:30' ], [ 0.3064, '07:30', '08:00' ], [ 0.3029, '05:00', '05:30' ], [ 0.3029, '05:30', '06:00' ], [ 0.302, '08:00', '08:30' ], [ 0.3016, '01:00', '01:30' ], [ 0.3016, '01:30', '02:00' ], [ 0.2995, '02:00', '02:30' ], [ 0.2995, '02:30', '02:00' ], [ 0.2961, '03:00', '03:30' ], [ 0.2961, '03:30', '04:00' ], [ 0.2954, '04:00', '04:30' ], [ 0.2954, '04:30', '05:00' ], [ 0.2782, '14:00', '14:30' ], [ 0.2782, '14:30', '15:00' ], [ 0.2667, '10:00', '10:30' ], [ 0.2667, '10:30', '11:00' ], [ 0.2522, '11:00', '11:30' ], [ 0.2522, '11:30', '12:00' ], [ 0.2492, '12:00', '12:30' ], [ 0.2492, '12:30', '13:00' ], [ 0.2492, '13:00', '13:30' ], [ 0.2492, '13:30', '14:00' ] ]; let max = 0; for(const ele of arr) { if(ele[0] > max) max = ele[0]; }; log(max);
Hallo @paul53,
könntest du mit bitte noch sagen, wie ich aus dem Array mit der schleife den kleinsten Wert ausgebe?
Danke und Grüße! -
@diamand2k22 sagte: mit der schleife den kleinsten Wert ausgebe?
const arr = [ [ 0.3781, '17:00', '17:30' ], [ 0.3781, '17:30', '18:00' ], [ 0.375, '18:00', '18:30' ], [ 0.375, '18:30', '19:00' ], [ 0.3569, '19:00', '19:30' ], [ 0.3569, '19:30', '20:00' ], [ 0.3488, '16:00', '16:30' ], [ 0.3488, '16:30', '17:00' ], [ 0.3422, '20:00', '20:30' ], [ 0.3422, '20:30', '21:00' ], [ 0.3369, '22:00', '22:30' ], [ 0.3369, '22:30', '23:00' ], [ 0.3349, '21:00', '21:30' ], [ 0.3349, '21:30', '22:00' ], [ 0.3343, '15:00', '15:30' ], [ 0.3343, '15:30', '16:00' ], [ 0.3242, '23:00', '23:30' ], [ 0.3242, '23:30', '00:00' ], [ 0.3113, '00:00', '00:30' ], [ 0.3113, '00:30', '01:00' ], [ 0.3078, '06:00', '06:30' ], [ 0.3078, '06:30', '07:00' ], [ 0.3064, '07:00', '07:30' ], [ 0.3064, '07:30', '08:00' ], [ 0.3029, '05:00', '05:30' ], [ 0.3029, '05:30', '06:00' ], [ 0.302, '08:00', '08:30' ], [ 0.3016, '01:00', '01:30' ], [ 0.3016, '01:30', '02:00' ], [ 0.2995, '02:00', '02:30' ], [ 0.2995, '02:30', '02:00' ], [ 0.2961, '03:00', '03:30' ], [ 0.2961, '03:30', '04:00' ], [ 0.2954, '04:00', '04:30' ], [ 0.2954, '04:30', '05:00' ], [ 0.2782, '14:00', '14:30' ], [ 0.2782, '14:30', '15:00' ], [ 0.2667, '10:00', '10:30' ], [ 0.2667, '10:30', '11:00' ], [ 0.2522, '11:00', '11:30' ], [ 0.2522, '11:30', '12:00' ], [ 0.2492, '12:00', '12:30' ], [ 0.2492, '12:30', '13:00' ], [ 0.2492, '13:00', '13:30' ], [ 0.2492, '13:30', '14:00' ] ]; let max = 0; let min = 99; for(const ele of arr) { if(ele[0] > max) max = ele[0]; if(ele[0] < min) min = ele[0]; }; log(max); log(min);
-
perfekt! Funktioniert, wie immer vielen Danke für die schnelle Hilfe!!
-
@paul53 said in Zeiten filtern Array:
@diamand2k22 sagte: mit der schleife den kleinsten Wert ausgebe?
const arr = [ [ 0.3781, '17:00', '17:30' ], [ 0.3781, '17:30', '18:00' ], [ 0.375, '18:00', '18:30' ], [ 0.375, '18:30', '19:00' ], [ 0.3569, '19:00', '19:30' ], [ 0.3569, '19:30', '20:00' ], [ 0.3488, '16:00', '16:30' ], [ 0.3488, '16:30', '17:00' ], [ 0.3422, '20:00', '20:30' ], [ 0.3422, '20:30', '21:00' ], [ 0.3369, '22:00', '22:30' ], [ 0.3369, '22:30', '23:00' ], [ 0.3349, '21:00', '21:30' ], [ 0.3349, '21:30', '22:00' ], [ 0.3343, '15:00', '15:30' ], [ 0.3343, '15:30', '16:00' ], [ 0.3242, '23:00', '23:30' ], [ 0.3242, '23:30', '00:00' ], [ 0.3113, '00:00', '00:30' ], [ 0.3113, '00:30', '01:00' ], [ 0.3078, '06:00', '06:30' ], [ 0.3078, '06:30', '07:00' ], [ 0.3064, '07:00', '07:30' ], [ 0.3064, '07:30', '08:00' ], [ 0.3029, '05:00', '05:30' ], [ 0.3029, '05:30', '06:00' ], [ 0.302, '08:00', '08:30' ], [ 0.3016, '01:00', '01:30' ], [ 0.3016, '01:30', '02:00' ], [ 0.2995, '02:00', '02:30' ], [ 0.2995, '02:30', '02:00' ], [ 0.2961, '03:00', '03:30' ], [ 0.2961, '03:30', '04:00' ], [ 0.2954, '04:00', '04:30' ], [ 0.2954, '04:30', '05:00' ], [ 0.2782, '14:00', '14:30' ], [ 0.2782, '14:30', '15:00' ], [ 0.2667, '10:00', '10:30' ], [ 0.2667, '10:30', '11:00' ], [ 0.2522, '11:00', '11:30' ], [ 0.2522, '11:30', '12:00' ], [ 0.2492, '12:00', '12:30' ], [ 0.2492, '12:30', '13:00' ], [ 0.2492, '13:00', '13:30' ], [ 0.2492, '13:30', '14:00' ] ]; let max = 0; let min = 99; for(const ele of arr) { if(ele[0] > max) max = ele[0]; if(ele[0] < min) min = ele[0]; }; log(max); log(min);
Hallo @paul53,
noch ein Anliegen, könntest du mir bei der vorhandenen Konstellation sagen, wie ich aus dem Array den durchschnittlichen Wert ausgebe?
Danke nochmal für deine Hilfe und Grüße!
-
@diamand2k22 sagte: den durchschnittlichen Wert ausgebe?
let max = 0; let min = 99; let sum = 0; for(const ele of arr) { if(ele[0] > max) max = ele[0]; if(ele[0] < min) min = ele[0]; sum += ele[0]; }; log(max); log(min); log(sum / arr.length); // Durchschnitt
-
-
Hallo Paul,
hab folgendes Array, vorgefiltert mit z.B. Zeiten ab 0:00
[ [ 0.3839, '17:00', '17:30' ], [ 0.3839, '17:30', '18:00' ], [ 0.3766, '18:00', '18:30' ], [ 0.3766, '18:30', '19:00' ] ]
Die Variable sunup = 8:30 Uhr
async function filterZeit(arrZeit, sunup) { const newArray = []; for (let i = 0; i < arrZeit.length; i++) { const startTime = parseInt(arrZeit[i][1].split(':')[0]); newArray.push(arrZeit[i]); if (startTime == sunup.split(':')[0]) { break; } } newArray.sort(function (a, b) { return b[0] - a[0]; }); return newArray; }
jetzt soll das Skript die Zeiten zwischen 0:00 Uhr und 08:30 Uhr aus dem Array ausgeben.
Wenn jetzt Zeiten zwischen 0:00 Uhr und 8:30 Uhr im Array sind, werden die auch ausgegeben, aber wenn keine Zeiten zwischen 00:00 Uhr und 8:30 Uhr enthalten sind, wir aber trotzdem das Array mit Zeiten größer > 8:30 Uhr ausgebenwie bekomm ich es hin, dass dann ein leeres array [] ausgegeben wird?
-
@diamand2k22 sagte: leeres array [] ausgegeben wird?
Zeile 6:
if(startTime <= sunup.split(':')[0]) newArray.push(arrZeit[i]);
-