question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

suggestion to standardize Iterate callback's arguments

See original GitHub issue

Wouldn’t it be better to standardize the callback in iterate with (value, index|key, target)?

in iterate.js:

line 21

callback(target[i], i)

vs line 27 (Array.prorotype.forEach)

target.forEach(callback)

Also, if callback returns false break the loop.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Yomguitherealcommented, Feb 13, 2017

Hello @Rayraegah. The difference between both lines you show is the target scope, no? But since this function is only used internally and is not exposed, why do we need the target scope?

I cannot break the loop if callback returns false. What if false is actually a value you are iterating upon?

0reactions
Rayraegahcommented, Feb 13, 2017

Since we need to consume the iterator, I guess this is to be expected, no?

When you add a new data-structure that would need this feature, then you can modify iterator 😃 otherwise its okay.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js: How do you handle callbacks in a loop?
Q: What is the best way in Node.js to 1) get the result of the first async call, 2) iterate through the list,...
Read more >
The Good and Bad of JavaScript Callbacks - Bits and Pieces
The callback function — including its references — is passed as an argument to other functions. The functions that receive the callback function...
Read more >
How to iterate over a callback n times in JavaScript
The callback is a function that is passed as an argument. for iterate ... Approach 1: We use recursion to iterate n times...
Read more >
xgboost source: R/callbacks.R - Rdrr.io
When a callback function has \code{finalize} parameter, its finalizer part will ... The iteration evaluation result \code{bst_evaluation} must be a named ...
Read more >
Mastering Hard Parts of JavaScript: Callbacks III
The callback will return either true or false. prioritize will iterate through the array and perform the callback on each element, and return...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found