Тёмный

How JavaScript's Array Reduce Works -  

Wes Bos
Подписаться 178 тыс.
Просмотров 15 тыс.
50% 1

Наука

Опубликовано:

 

19 сен 2017

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 24   
@rotrose7531
@rotrose7531 4 года назад
You are genius, thank you. I learnt a lot from this tutorial.
@antonbodnia5788
@antonbodnia5788 5 лет назад
another great way const measuredTime = new Date(null); measuredTime.setSeconds(17938); const MHSTime = measuredTime.toISOString().substr(11, 8); "04:58:58"
@abdelrahman5094
@abdelrahman5094 4 года назад
what does substr(11,8) do in this code?
@Suneriins234
@Suneriins234 4 года назад
@@abdelrahman5094 substr(11,8) = Substr(skipallnumbersbeforethisnumber, Outputcharacterslength)).....If you "console.log" this ""const measuredTime = new Date(null); measuredTime.setSeconds(17938); const MHSTime = measuredTime.toISOString()."; you will get this "2020-06-22T10:28:58.918" Because we want to removed "2020-06-22T" and only want to have result in "10:28:58" .Therefore we use "substr(start,lenght)"..substr() will substract all starting numbers and give us result in 8 characters."substr(11.8)..
@MatthewPeck_personal
@MatthewPeck_personal 6 лет назад
How do you have the gutter symbols? Looks like a Git package, or is this Atom?
@limerence-00
@limerence-00 6 лет назад
you actually enable my studying)
@anonim1468
@anonim1468 6 лет назад
WITH REDUCE const timeNodes = Array.from(document.querySelectorAll('[data-time]')); let seconds = timeNodes.reduce( (total, current, index) => { let [min, sec] = current.dataset.time.split(":").map(parseFloat); return total += min * 60 + sec; }, 0); let hour = seconds / 3600
@lassmadaddeln
@lassmadaddeln 5 лет назад
Just a quick note: Since you're not using index i guess you could just omit it.
@elanf
@elanf 6 лет назад
Hey Wes! What’s your intro song?
@margaritabozhenova8473
@margaritabozhenova8473 4 года назад
Without .map and parseFloat(): const seconds = timeNodes.reduce((total, currValue) => { const [mins, secs] = currValue.dataset.time.split(":"); return total + (mins * 60 + secs * 1); }, 0);
@nathancornwell1455
@nathancornwell1455 4 года назад
So, are they automatically coerced into numbers from strings ?
@margaritabozhenova8473
@margaritabozhenova8473 4 года назад
Nathan Cornwell if a String is multiplied by a number, it becomes a number
@nathancornwell1455
@nathancornwell1455 4 года назад
Well, i just learned something new . Implicit type coercion .
@uzair004
@uzair004 4 года назад
beautiful one liner :)
@singhkr
@singhkr Год назад
perfect
@snehasamuel7426
@snehasamuel7426 Год назад
but why are we doing only floor and not ceil ? Will it be wrong if we do ceil ?
@shiningdragon8737
@shiningdragon8737 6 лет назад
How did you get the 3600?
@dominaiter2957
@dominaiter2957 6 лет назад
1 hour = 3600 seconds.
@jean-francoisbouzereau6258
@jean-francoisbouzereau6258 4 года назад
At 5:36. (mins*60)+(secs*1). would have done the trick
@jaimeandrescarcamosepulved2456
I wrote a function that takes in seconds' result and returns totalVidTime. Great video! learning a ton with this series. function totalVidTime(seconds){ let hours =Math.floor(seconds/3600); let minutes =Math.floor((seconds/3600%1)*60); let secnd = Math.floor(((seconds/3600%1*60)%1)*60); return `${hours}:${minutes}:${secnd}`; }
Далее
ELA NÃO ESPERAVA POR ISSO 🥶 ATTITUDE #shorts
00:20
Ajax Type Ahead with fetch() - #JavaScript30 6/30
17:22
Learn Web Design For Beginners - Full Course (2024)
3:07:31
Crust of Rust: async/await
2:34:01
Просмотров 187 тыс.
Why The Windows Phone Failed
24:08
Просмотров 221 тыс.