Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c8a7ee9

Browse files
committed
Modified all the for loops so as to remove eslint compliance.
1 parent 76a1726 commit c8a7ee9

File tree

1 file changed

+29
-40
lines changed

1 file changed

+29
-40
lines changed

homework/index.js

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636

3737
divElement.push('<div id="header">', `${'<h3>'} Contributions: ${'</h3>'} ${'</div>'}`);
3838

39-
// eslint-disable-next-line no-restricted-syntax
40-
for (const details of contribution) {
39+
contribution.forEach(details => {
4140
divElement.push(
4241
'<ul>',
4342
`${'<li>'} ${'<img src="'}${details.avatar_url}" width="40" height="40">`,
@@ -46,7 +45,7 @@
4645
`<li>${details.contributions}</li>`,
4746
'</ul>',
4847
);
49-
}
48+
});
5049

5150
const htmlString = divElement.join('');
5251
document.getElementById('contributor-information').innerHTML = htmlString;
@@ -57,36 +56,30 @@
5756
function loadRepoDetails(repoInfo, optionValue) {
5857
const templateElement = [];
5958

60-
// eslint-disable-next-line no-restricted-syntax
61-
for (const repo in repoInfo) {
62-
if (Object.prototype.hasOwnProperty.call(repoInfo, repo)) {
63-
if (optionValue === repoInfo[repo].name) {
64-
// format the date
65-
const upDate = new Date(repoInfo[repo].updated_at);
66-
const amOrPm = upDate.getHours() < 12 ? 'AM' : 'PM';
67-
const dateHours = upDate.getHours() % 12 || 12;
68-
const formatedUpdate = `${upDate.getMonth()}/${upDate.getDate()}/${upDate.getFullYear()} ${dateHours}
59+
Object.keys(repoInfo).forEach(key => {
60+
if (optionValue === repoInfo[key].name) {
61+
// format the date
62+
const upDate = new Date(repoInfo[key].updated_at);
63+
const amOrPm = upDate.getHours() < 12 ? 'AM' : 'PM';
64+
const dateHours = upDate.getHours() % 12 || 12;
65+
const formatedUpdate = `${upDate.getMonth()}/${upDate.getDate()}/${upDate.getFullYear()} ${dateHours}
6966
: ${upDate.getMinutes()}:${upDate.getSeconds()} ${amOrPm}`;
70-
71-
templateElement.push(
72-
'<div id="row">',
73-
`${'<p id="name-info">'} Repository name : ${'<a href="'}${
74-
repoInfo[repo].html_url
75-
}"${'/>'} ${repoInfo[repo].name}</a></p>`,
76-
`${'<p id="desc">'} Description : ${repoInfo[repo].description}</p>`,
77-
`${'<p id="forks">'} Forks : ${repoInfo[repo].forks_count}</p>`,
78-
79-
`${'<p id="updated">'} Updated : ${formatedUpdate}</p>`,
80-
'</div>',
81-
);
82-
83-
// Call another function(addContributors) to fill i contributor information.
84-
fetchUrl(repoInfo[repo].contributors_url).then(responseData => {
85-
addContributors(responseData);
86-
});
87-
}
67+
templateElement.push(
68+
'<div id="row">',
69+
`${'<p id="name-info">'} Repository name : ${'<a href="'}${
70+
repoInfo[key].html_url
71+
}"${'/>'} ${repoInfo[key].name}</a></p>`,
72+
`${'<p id="desc">'} Description : ${repoInfo[key].description}</p>`,
73+
`${'<p id="forks">'} Forks : ${repoInfo[key].forks_count}</p>`,
74+
75+
`${'<p id="updated">'} Updated : ${formatedUpdate}</p>`,
76+
'</div>',
77+
);
78+
fetchUrl(repoInfo[key].contributors_url).then(responseData => {
79+
addContributors(responseData);
80+
});
8881
}
89-
}
82+
});
9083
const htmlString = templateElement.join('');
9184
document.getElementById('repo-details').innerHTML = htmlString;
9285
}
@@ -100,25 +93,21 @@
10093

10194
// push all the HYP repo names to sort array.
10295

103-
// eslint-disable-next-line no-restricted-syntax
104-
for (const repo in userRepo) {
105-
if (Object.prototype.hasOwnProperty.call(userRepo, repo)) {
106-
sortRepoName.push(userRepo[repo].name);
107-
}
108-
}
96+
Object.keys(userRepo).forEach(key => {
97+
sortRepoName.push(userRepo[key].name);
98+
});
10999

110100
// sort the repo name using sort function and localeComapare for uppercase and lowercase sorting.
111101
sortRepoName.sort((a, b) => a.localeCompare(b));
112102

113103
// Create Option under Select element and attach the same with SELECT element.
114104

115-
// eslint-disable-next-line no-restricted-syntax
116-
for (const repo of sortRepoName) {
105+
sortRepoName.forEach(repo => {
117106
const option = document.createElement('option');
118107
option.value = repo;
119108
option.text = repo;
120109
selectRepo.appendChild(option);
121-
}
110+
});
122111

123112
const selectBox = document.getElementById('select-repo');
124113

0 commit comments

Comments
 (0)