Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.