Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
**/node_modules/
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions week-2/Week-2-Assignments/02-nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions week-2/Week-2-Assignments/02-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"testTimeout": 10000
},
"dependencies": {
"cors": "^2.8.5",
"express": "^4.18.2",
"uuid": "^9.0.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
Testing the server - run `npm run test-fileServer` command in terminal
*/
const express = require('express');
const cors = require('cors')
// biome-ignore lint/style/useNodejsImportProtocol: <explanation>
const fs = require('fs');
// biome-ignore lint/style/useNodejsImportProtocol: <explanation>
const path = require('path');
const app = express();

app.use(cors)

app.get('/files', (req, res) => {
fs.readdir(path.join(__dirname, './files/'), (err, files) => {
if (err) {
Expand All @@ -45,4 +50,5 @@ app.all('*', (req, res) => {
res.status(404).send('Route not found');
});

module.exports = app;
// module.exports = app;
app.listen(3000)
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const express = require('express');
const cors = require("cors");
const bodyParser = require('body-parser');
// biome-ignore lint/style/useNodejsImportProtocol: <explanation>
const fs = require("fs");

const app = express();

app.use(cors)
app.use(bodyParser.json());

function findIndex(arr, id) {
Expand All @@ -14,7 +16,7 @@ function findIndex(arr, id) {
}

function removeAtIndex(arr, index) {
let newArray = [];
const newArray = [];
for (let i = 0; i < arr.length; i++) {
if (i !== index) newArray.push(arr[i]);
}
Expand All @@ -32,7 +34,7 @@ app.get('/todos/:id', (req, res) => {
fs.readFile("todos.json", "utf8", (err, data) => {
if (err) throw err;
const todos = JSON.parse(data);
const todoIndex = findIndex(todos, parseInt(req.params.id));
const todoIndex = findIndex(todos, Number.parseInt(req.params.id));
if (todoIndex === -1) {
res.status(404).send();
} else {
Expand All @@ -58,11 +60,14 @@ app.post('/todos', (req, res) => {
});
});




app.put('/todos/:id', (req, res) => {
fs.readFile("todos.json", "utf8", (err, data) => {
if (err) throw err;
const todos = JSON.parse(data);
const todoIndex = findIndex(todos, parseInt(req.params.id));
const todoIndex = findIndex(todos, Number.parseInt(req.params.id));
if (todoIndex === -1) {
res.status(404).send();
} else {
Expand All @@ -84,8 +89,8 @@ app.delete('/todos/:id', (req, res) => {

fs.readFile("todos.json", "utf8", (err, data) => {
if (err) throw err;
const todos = JSON.parse(data);
const todoIndex = findIndex(todos, parseInt(req.params.id));
let todos = JSON.parse(data);
const todoIndex = findIndex(todos, Number.parseInt(req.params.id));
if (todoIndex === -1) {
res.status(404).send();
} else {
Expand All @@ -103,4 +108,5 @@ app.use((req, res, next) => {
res.status(404).send();
});

module.exports = app;
// module.exports = app;
app.listen(3000)
6 changes: 6 additions & 0 deletions week-2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion week-3/01-reconciler/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<body>
<div id="mainArea"></div>
<script src="script-ugly.js"></script>
<script src="reconciler.js"></script>
</body>

</html>
64 changes: 64 additions & 0 deletions week-3/01-reconciler/reconciler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
function createDomElements(data) {
var parentElement = document.getElementById('mainArea')
var currentChildren = Array.from(parentElement.children);

let added = 0, deleted = 0, updated = 0;

data.forEach(function (item) {
var existingChild = currentChildren.find(function (child) {
return child.dataset.id === String(item.id);
});

if (existingChild) {
updated++;
existingChild.children[0].innerHTML = item.title;
existingChild.children[1].innerHTML = item.description

currentChildren = currentChildren.filter(function (child) {
return child != existingChild;
})

} else {
added++;
var childElement = document.createElement("div")
childElement.dataset.id = item.id

var grandChildElement1 = document.createElement("span");
grandChildElement1.innerHTML = item.title

var grandChildElement2 = document.createElement("span");
grandChildElement2.innerHTML = item.description

var grandChildElement3 = document.createElement("button");
grandChildElement3.innerHTML = "Delete"
grandChildElement3.setAttribute("onclick", "deleteTodo(" + item.id + ")")

childElement.appendChild(grandChildElement1)
childElement.appendChild(grandChildElement2)
childElement.appendChild(grandChildElement3)
parentElement.appendChild(childElement);
}

})

currentChildren.forEach(function(child){
deleted++;
parentElement.removeChild(child);
})
console.log(added)
console.log(updated)
console.log(deleted)
}

window.setInterval(() => {
let todos = [];
for (let i = 0; i<Math.floor(Math.random() * 100); i++) {
todos.push({
title: "Go to gym",
description: "Go to gym form 5",
id: i+1
})
}

createDomElements(todos)
}, 5000)
Loading