Just wondering what's the equivalent of the each do function from Ruby to JS?
For example:
$data_actors.each do | actor | #do stuff here endThanks in advance.
If your Ruby equivalent has return inside the each do:
for (var index = 0, length = $dataActors.length; index < length; index++) { // do stuff here if (cond) { continue; } // do stuff here}
It depends on how your code's actually writtenThanks. It is working now, but I wonder why it says that the actor is undefined but when I log it, it says its an Actor object. Figures.
The below is the equivalent of the above Ruby code:
for (var index = 0, length = $dataActors.length; index < length; index++) { // do stuff here if (cond) { return; } // do stuff here}
$dataActors.some(function(actor){
if(cond) {return true}
})
Just to add that a functional equivalent of this code can be achieved using `Array#some` in this way:
$dataActors.some(function(actor){
if(cond) {return true}
})
A bit off topic: Is there any simple and small functional equivalent of the below imperative code?
var data = this.patb_note_data();
for (var index = 0, length = data.length; index < length; index++) {
for (var d = data[index], i = 0, l = d.length; i < l; i++) {
if (d.meta[note]) { return d.meta[note]; }
}
}
return null;
I've tried to write a functional equivalent but it ended up to be much more complicated and convoluted than this imperative one lol