Link to home
Start Free TrialLog in
Avatar of juan field
juan field

asked on

regarding the code you wrote. I am new in JS . where does your code goes and how does it apply ? I think you wrote it down but i cant seem to understand just yet.

I had this question after viewing how can i test my code?.

function every(array, callbackFunction) {
  var doesEveryElementMatch = true;
  array.forEach(function(element) {
    doesEveryElementMatch = callbackFunction(element);
  });
  return doesEveryElementMatch;
}

// when i  am going to test the question what is the callbackfunction i am supposed to write down?
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

I am sorry but I don't understand what you are asking? Is this a different question from the one in the other thread or are you asking a question about something in that thread? If the latter then please post to that thread directly. If this is a different question please state what your question is.
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if you change that every Function code to -
function every(array, callbackFunction) {
  var doesEveryElementMatch = true;
  array.forEach(function(element) {
    if (doesEveryElementMatch)
       doesEveryElementMatch = callbackFunction(element);
  });
  return doesEveryElementMatch;
}

Open in new window


it offers a better chance of doing what the array Method does.
Avatar of juan field
juan field

ASKER

thank you slick812...
I just closed the var doesEveryElementMatch to true so i would be able to check the inspections. Really JS is a different taste  to my palate .. i like it , just getting use to the rules.
the more conventional javascript FOR loop for ARRAY elements access can sometimes be better (my opinion) than the array.forEach( ), because u can use the LOOP break; and  continue; operations, which I could not get to work in the array.forEach( ) operations