4/6 something interesting to me


#1

within the instructions:
3. ...create a for loop that cycles from 0 up to one less than the number of items in the contacts array...

This is the syntex I wrote that worked for the exercise:

var contacts = [bob, mary];

function printPerson(person) {
console.log(person.firstName + " " + person.lastName);
};

var list = function() {
//contactsLength stores the number of items in the contacts array
var contactsLength = contacts.length;
for (var i = 0; i < contactsLength; i++) {
printPerson(contacts[i]);
}
};
list();

But at first I tried specifying with in the for loop :

for (var i = 0; i < contactsLength - 1; i++) {
printPerson(contacts[i]);
}

notice the minus one, as I understood instructed. To my understanding, only Bob was ment to be printed to the console, according to instruction 3,
I'm just curious...going through most forum threads about this exercise, I couldn't find anyone referring to it.

Thank you a lot in advance
Happy Holidays! :smile:


#2

You're using the less than operator, which will be true up to one less than the value compared to

5 < 6 // true
6 < 6 // false

#3

so, that is why no need for "-1", right!

I could be so anal sometimes, over thinking about stuff :stuck_out_tongue:
Thank you!