1.10) Exercise 3 (Lists) Solution | The Complete (FREE) Flutter Course

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ต.ค. 2024

ความคิดเห็น • 19

  • @michaelschneider729
    @michaelschneider729 3 ปีที่แล้ว +1

    And here's my solution:
    String lpad2(int value) => '$value'.padLeft(2, '0');
    String formatTime(int minutes) =>
    '${lpad2(minutes ~/ 60)}:${lpad2(minutes % 60)}';
    void main() {
    const quaterHoursPerDay = 24 * 4;
    final timeFormatted = [for (var i = 0; i < quaterHoursPerDay; i++) i * 15]
    .map(formatTime)
    .toList();
    timeFormatted.forEach(print);
    }
    Ok, I'm using list-for which you didn't mention, but the initial list of quarter hours can on course be built from an empty list by adding the values in a for-loop equal to my list-for.

  • @SaveaBowls
    @SaveaBowls 3 ปีที่แล้ว

    First, let me say that I started watching your videos because you give a more complete overview of proper OOP than many others I've seen on youtube. I was just looking for a quick overview on Dart "Classes" and you were the first person I have ever seen that actually mentions getters and setters from a security standpoint. As you probably know - JS does't have private properties so I tended to use a functional programming approach when using it. I never took a programming course and I am really just a hobbiest at the moment, but I figured I could probably learn some good stuff from you.

  • @sb-jo2ch
    @sb-jo2ch 3 ปีที่แล้ว +1

    nested loop
    void main() {
    List fifteenMinuteIncrements = [];
    for (int hr=0; hr

  • @mohammedsadiq1567
    @mohammedsadiq1567 3 ปีที่แล้ว

    I completed the entire module 1 in one sit!
    Great content, mate!

  • @Jan123.
    @Jan123. 3 ปีที่แล้ว +1

    Nice one (though this modulo stuff is still hard for me. I did use nested for-loops.)

  • @Ester_Krupova
    @Ester_Krupova 3 ปีที่แล้ว

    Why is the tempStr in if-else statement instead of just tempStr = '${hours > 9 ? hours : '0$hours'}:'; ? When the value of hours is 0, it looks the same as the String in else { }.

    • @ovidiusmazuru9201
      @ovidiusmazuru9201  3 ปีที่แล้ว +1

      Great point. I was probably just distracted trying to record and code at the same time (it's much easier now, but it did not come naturally at first). Looking at the code now, I see no reason to include that extra if else

  • @paulvickers8059
    @paulvickers8059 4 ปีที่แล้ว +1

    I have a solution I will post before watching this video, it works, but I am not sure I am doing all you are asking, as i didn't use the map function, I didn't understand it that well, I just used lists and for loops.
    void main() {
    exercise3Solution();
    }
    exercise3Solution() {

    List hour = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23'];
    List minutes = ['00', '15', '30', '45'];

    int i2;

    for(int i =0; i < hour.length; i++) {
    for(int i2 = 0; i2 < minutes.length; i2++){
    print('${hour[i]}:${minutes[i2]}');
    }
    }
    }

    • @ovidiusmazuru9201
      @ovidiusmazuru9201  4 ปีที่แล้ว +2

      It's a good solution; it works. One tiny tiny thing though, rather than using i2 in the 2nd for loop, usually we'd use j. Then k if you have a 3rd loop and so on

    • @paulvickers8059
      @paulvickers8059 4 ปีที่แล้ว +1

      @@ovidiusmazuru9201 thanks that's good to know, I was thinking what to use, so I just thought i2, I thought the I was for index, so I thought index 2, but I will use j in future, i2 doesn't look good.

  • @mohammedsadiq1567
    @mohammedsadiq1567 3 ปีที่แล้ว

    void main() {
    List list = generateTime();
    for(int i = 0; i < list.length; i++){
    print(list[i]);
    }
    }
    List generateTime(){
    List myList = [];
    int startPreColon = 0;
    int startPostColon = 0;
    String preColon = "";
    String postColon = "";
    while(true){
    postColon = handleTime(startPostColon, 60);
    preColon = handleTime(startPreColon, 24);
    myList.add(preColon + ":" + postColon);
    startPostColon += 15;
    if(startPostColon % 60 == 0) startPreColon += 1;
    if((startPreColon) == 24 && (startPostColon % 60 == 0)) break;
    }
    return myList;
    }
    String handleTime(int number, int modulo){
    int result = number % modulo;
    if(result < 10){
    return "0" + result.toString();
    }
    return result.toString();
    }