Movatterモバイル変換


[0]ホーム

URL:


Sorry, we no longer support your browser
Please upgrade toMicrosoft Edge,Google Chrome, orFirefox. Learn more about ourbrowser support.
Skip to main content
Stack Overflow
  1. About
  2. For Teams
Loading…
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Timeline forLoop through an array in JavaScript

Current License: CC BY-SA 4.0

26 events
when toggle formatwhatbylicensecomment
Nov 13, 2022 at 21:52historyeditedKamil KiełczewskiCC BY-SA 4.0
new tests
Mar 1, 2021 at 5:21commentadded Kamil Kiełczewski @Pitouli you are right - I rollback answer to its initial form. When I have more time then I will perform benchamarks again
Mar 1, 2021 at 5:17historyrollbackKamil Kiełczewski
Rollback to Revision 1
Mar 1, 2021 at 3:52commentadded Pitouli Careful! The benchmark is wrong, because the array is not reset between each execution. Since the shift() has emptied the array after the first execution, all the subsequent executions are indeed extremely fast :p When you correctly reset the array, it appears that this solution is the second slowest.jsbench.me/4dklq1kjef/1
Nov 9, 2020 at 20:03commentadded Arthur S This isn't esoteric. Its simply unnecessary and makes an assumption that thea variable will not be used in further code.
Oct 30, 2020 at 8:35commentadded Peter Mortensen Even if it does not exist in your native language, you should not leave out articles in English (the indefinite article ("a" or "an") and the definite article ("the")). See e.g.English Articles - 3 Simple Rules To Fix Common Grammar Mistakes & Errors andA, AN, THE - Articles in English.
Oct 30, 2020 at 8:33historyeditedPeter MortensenCC BY-SA 4.0
Active reading [<https://www.youtube.com/watch?v=1Dax90QyXgI&t=17m54s> <https://www.youtube.com/watch?v=1Dax90QyXgI&t=19m05s>].
Aug 9, 2020 at 7:26historyeditedKamil KiełczewskiCC BY-SA 4.0
deleted 10 characters in body
Aug 6, 2020 at 8:07historyeditedKamil KiełczewskiCC BY-SA 4.0
edited body
Aug 6, 2020 at 8:01historyeditedKamil KiełczewskiCC BY-SA 4.0
added 351 characters in body
Aug 5, 2020 at 22:11historyeditedKamil KiełczewskiCC BY-SA 4.0
added 180 characters in body
Aug 5, 2020 at 21:47historyeditedKamil KiełczewskiCC BY-SA 4.0
deleted 2 characters in body
Aug 5, 2020 at 7:05historyeditedKamil KiełczewskiCC BY-SA 4.0
added 2 characters in body
Aug 5, 2020 at 6:30historyeditedKamil KiełczewskiCC BY-SA 4.0
deleted 5 characters in body
Aug 5, 2020 at 6:13historyeditedKamil KiełczewskiCC BY-SA 4.0
deleted 5 characters in body
Aug 4, 2020 at 21:29historyeditedKamil KiełczewskiCC BY-SA 4.0
added 2 characters in body
Aug 4, 2020 at 21:23commentadded Kamil Kiełczewski @Sapphire_Brick - thank you for your comment - I tink using console.log in tests is not good because it is complex system function and have big impact on run time. I check withr+=a[i].length (sum of words length) for array witch 1000 elements - and still this solution was much faster than other solution (and probaly the speed difference grow when number of elements grow...) - I'm surprised too that this solution is so fast :)
Aug 4, 2020 at 21:18historyeditedKamil KiełczewskiCC BY-SA 4.0
deleted 4 characters in body
Aug 4, 2020 at 21:11historyeditedKamil KiełczewskiCC BY-SA 4.0
added 231 characters in body
Aug 4, 2020 at 21:02historyeditedKamil KiełczewskiCC BY-SA 4.0
added 231 characters in body
Aug 4, 2020 at 20:51commentadded Sapphire_Brick You have make a good point. I ran your example with an array of 1000 items, andwhile(a.length) { console.log(a.shift()); } was about twice as fast as thefor(var i = 0; i < a.length; i++) { console.log(a[i]); } version. ¯\_(ツ)_/¯
Jul 24, 2020 at 22:04commentadded Kamil Kiełczewski @Sapphire_Brick don't be lazy! :) you can check it your self- I give you link (test) to tool in above comment. However for small array case (as OP uses) when you need to optimize speed you should choose solution fastest for small arrays (not for big arrays - which can be different)
Jul 24, 2020 at 21:24commentadded Sapphire_Brick Of course a simple program like this is fast, but how does it scale in comparison tofor(...;...;...) orfor(... of ...)?
Jul 24, 2020 at 10:06commentadded Kamil Kiełczewski @Sapphire_Brick actually it is quite fast - here istest
Jan 16, 2020 at 2:49commentadded Sapphire_Brick that's the Haskell-y way to do it; keep taking the first one. clever, but probably slow.
Dec 19, 2019 at 6:40history answeredKamil KiełczewskiCC BY-SA 4.0
toggle format

[8]ページ先頭

©2009-2025 Movatter.jp