We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
So elegant! I always forget about it and end up using reduce.
It is fast too. Granted, it's by a little margin and only ~8 / 10 times, but still, it's a winner:
# Benchmark.bmbm on an array of 100000 * 7 digits integersRehearsal-------------------------------------------sum0.0001570.0000020.000159(0.000157)reduce0.0001830.0000030.000186(0.000187)each0.0064230.0000010.006424(0.006429)----------------------------------total:0.006769secusersystemtotalrealsum0.0001400.0000020.000142(0.000139)reduce0.0001700.0000020.000172(0.000171)each0.0067280.0000340.006762(0.006841)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Simple Array Sum
You are viewing a single comment's thread. Return to all comments →
So elegant! I always forget about it and end up using reduce. It is fast too. Granted, it's by a little margin and only ~8 / 10 times, but still, it's a winner: