Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Update 2009-03-06-javascript-best-practices.md
Browse files Browse the repository at this point in the history
In the "Avoid nested loops" section:
Fixed one typo
Fixed several semantic errors in the code (see Pull comments)
  • Loading branch information
UberKluger authored Aug 7, 2021
1 parent 0fbafd0 commit 61fbef4
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/articles/_posts/2009-03-06-javascript-best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,8 @@ The other problem of nesting is variable names and loops. As you normally start

function renderProfiles(o) {
var out = document.getElementById('profiles');
var ul = document.createElement('ul');
for(var i = 0; i < o.members.length; i++) {
var ul = document.createElement('ul');
var li = document.createElement('li');
li.appendChild(document.createTextNode(o.members[i].name));
var nestedul = document.createElement('ul');
Expand All @@ -538,6 +538,7 @@ The other problem of nesting is variable names and loops. As you normally start
nestedul.appendChild(datali);
}
li.appendChild(nestedul);
ul.appendChild(li);
}
out.appendChild(ul);
}
Expand All @@ -546,26 +547,27 @@ As I am using the generic — really throw-away — variable names `ul` and `li`

function renderProfiles(o) {
var out = document.getElementById('profiles');
var ul = document.createElement('ul');
for(var i = 0; i < o.members.length; i++) {
var ul = document.createElement('ul');
var li = document.createElement('li');
li.appendChild(document.createTextNode(data.members[i].name));
li.appendChild(addMemberData(o.members[i]));
li.appendChild(document.createTextNode(o.members[i].name));
li.appendChild(addMemberData(o.members[i].data));
ul.appendChild(li);
}
out.appendChild(ul);
}
function addMemberData(member) {
function addMemberData(data) {
var ul = document.createElement('ul');
for(var i = 0; i < member.data.length; i++) {
for(var i = 0; i < data.length; i++) {
var li = document.createElement('li');
li.appendChild(
document.createTextNode(
member.data[i].label + ' ' +
member.data[i].value
data[i].label + ' ' +
data[i].value
)
);
ul.appendChild(li);
}
ul.appendChild(li);
return ul;
}

Expand Down

0 comments on commit 61fbef4

Please sign in to comment.