You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found you are always prevent to use for loop but for loop is better than while loop in case of determined loop steps. It's more reliable.
E.g:
function nonZero (len) {
var out = Buffer.allocUnsafe(len)
var i = 0
var cache = randomBytes(len * 2)
var cur = 0
var num
while (i < len) {
if (cur === cache.length) {
cache = randomBytes(len * 2)
cur = 0
}
num = cache[cur++]
if (num) {
out[i++] = num
}
}
return out
}
Could be:
function nonZero (len) {
var out = Buffer.allocUnsafe(len)
var cache = randomBytes(len * 2)
var num
for ( var i = 0, cur = 0; i < len; i++) {
if (cur === cache.length) {
cache = randomBytes(len * 2)
cur = 0
}
num = cache[cur++]
if (num) {
out[i] = num
}
}
return out
}
The text was updated successfully, but these errors were encountered:
I've found you are always prevent to use
for loop
butfor loop
is better thanwhile loop
in case of determined loop steps. It's more reliable.E.g:
Could be:
The text was updated successfully, but these errors were encountered: