Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions, Arrays, DOM #5

Merged
merged 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1-module/1-task/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ function factorial(n) {
}
return result;
}

2 changes: 1 addition & 1 deletion 3-module/1-task/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function namify(users) {
// ваш код...
return users.map((user) => user.name);
}
3 changes: 2 additions & 1 deletion 3-module/2-task/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
function filterRange(arr, a, b) {
// ваш код...
return arr.filter((x) => x >= a && x <= b);
}

2 changes: 1 addition & 1 deletion 3-module/3-task/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function camelize(str) {
// ваш код...
return str.split('-').map((substr, index) => index > 0 ? substr[0].toUpperCase() + substr.slice(1) : substr).join('');
}
5 changes: 4 additions & 1 deletion 3-module/4-task/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
function showSalary(users, age) {
// ваш код...
return users
.filter(user => user.age <= age)
.map(user => `${user.name}, ${user.balance}`)
.join('\n');
}
11 changes: 10 additions & 1 deletion 3-module/5-task/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
function getMinMax(str) {
// ваш код...
let result = str.split(' ')
.filter((substr) => {
if (Number(substr)) {
return substr;
}
})
.map((substr) => Number(substr))
.sort((a, b) => a - b);
return {min: result[0], max: result[result.length - 1]};
}

11 changes: 10 additions & 1 deletion 4-module/1-task/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
function makeFriendsList(friends) {
// ваш код...
let ul = document.createElement("ul");
for (let friend of friends) {
// Create a li element for each friend
let li = document.createElement("li");
// Set the text content of the li element to the friend's name
li.textContent = friend.firstName + " " + friend.lastName;
// Append the li element to the ul element
ul.appendChild(li);
}
return ul;
}
7 changes: 6 additions & 1 deletion 4-module/2-task/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
function checkEquality(str) {
let arr = str.split(':');
return arr[0] === arr[1];
}

function makeDiagonalRed(table) {
// ваш код...
Array.from(table.querySelectorAll("td")).forEach((node) => checkEquality(node.innerText) ? node.style.backgroundColor = "red" : {});
}
21 changes: 20 additions & 1 deletion 4-module/3-task/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
function modifyElement(trNode, tdNode) {
if (tdNode.getAttribute('data-available') === "true") {
trNode.classList.add("available");
} else if (tdNode.getAttribute('data-available') === "false") {
trNode.classList.add("unavailable");
} else {
trNode.hidden = true;
}
if (tdNode.innerText === "f") {
trNode.classList.add("female");
} else {
trNode.classList.add("male");
}
if (Number(tdNode.innerText) < 18) {
trNode.style = "text-decoration: line-through";
}
}


function highlight(table) {
// ваш код...
Array.from(table.querySelectorAll("tr")).forEach((trNode) => Array.from(trNode.children).forEach(tdNode => modifyElement(trNode, tdNode)));
}
Loading