Skip to content

Instantly share code, notes, and snippets.

@tomekc
Created February 16, 2020 22:59
Show Gist options
  • Save tomekc/c2691447dd491a16a1fd409ff33bbf07 to your computer and use it in GitHub Desktop.
Save tomekc/c2691447dd491a16a1fd409ff33bbf07 to your computer and use it in GitHub Desktop.
Zagnieżdżone pętle for w JavaScripcie
console.log(`Hi!`);
// Odpowiednik enuma w TypeScripcie
let ProjectType = {
CURRENT: "CURRENT",
CLOSED: "CLOSED"
}
let projectsOfUser1 = [
{ name: 'Proj1', type: ProjectType.CURRENT },
{ name: 'Proj2', type: ProjectType.CLOSED },
];
let projectsOfUser2 = [
{ name: 'Proj2', type: ProjectType.CLOSED },
{ name: 'Proj5', type: ProjectType.CURRENT },
];
let usersProjects = {
'User1': projectsOfUser1,
'User2': projectsOfUser2
};
function testAllUsers(userList) {
for (let user in userList) {
console.log(`Setting up all projects of ${user}`);
setProjects(userList[user], user);
}
}
function setProjects(projectList, userName) {
console.log('Setting up projects of user ' + userName + ' from list');
for (let projectInfo of projectList) {
let projectName = projectInfo.name;
let projectType = projectInfo.type;
if (projectType == ProjectType.CLOSED) {
testForClosedProject(projectName, userName);
} else if (projectType == ProjectType.CURRENT) {
testForCurrentProject(projectName, userName);
}
}
}
function testForClosedProject(projectName, userName) {
console.log(`Testing project in CLOSED state ${projectName} for user ${userName}`);
}
function testForCurrentProject(projectName, userName) {
console.log(`Testing project in CURRENT state ${projectName} for user ${userName}`);
}
// -------------------
// MAIN FUNCTION BELOW
testAllUsers(usersProjects);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment