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

Todo #43

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open

Todo #43

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ccc197a
update package.json
anshsgit Aug 25, 2024
23738a2
update package-lock.json
anshsgit Aug 25, 2024
72b0b57
update time.js
anshsgit Aug 25, 2024
b9539d5
update palindrome.js
anshsgit Aug 25, 2024
dd3e654
update countVowels.js
anshsgit Aug 25, 2024
03705ba
update todo-list.js
anshsgit Aug 25, 2024
4153500
update calculator.js
anshsgit Aug 25, 2024
62c325c
update findLargestElement.js
anshsgit Aug 25, 2024
9ac7e1c
update expenditure-analysis.js
anshsgit Aug 25, 2024
dbf7911
update anagram.js
anshsgit Aug 25, 2024
194c10d
update 4-promise-chain.js
anshsgit Aug 25, 2024
321a84a
update 3-promise-all.js
anshsgit Aug 25, 2024
0cfbd8c
update 2-sleep-completely.js
anshsgit Aug 25, 2024
fe9bdc3
update 1-promisify-setTimeout.js
anshsgit Aug 25, 2024
ce7b2c3
Readme.md added
anshsgit Aug 30, 2024
1bd856f
index.html added
anshsgit Aug 30, 2024
11869cb
script.js added
anshsgit Aug 30, 2024
92fdb9d
styles.css added
anshsgit Aug 30, 2024
9af1885
Readme.md added
anshsgit Aug 30, 2024
2eee319
index.html added
anshsgit Aug 30, 2024
c19873b
script.js added
anshsgit Aug 30, 2024
121f3fc
styles.css added
anshsgit Aug 30, 2024
2b2ea7f
files added
anshsgit Aug 30, 2024
01af4a5
authenticationServer.js added
anshsgit Aug 30, 2024
d7314df
authorization.json added
anshsgit Aug 30, 2024
79d4a4a
file.txt added
anshsgit Aug 30, 2024
fdf105c
fileServer.js added
anshsgit Aug 30, 2024
36c1f6f
noOfWord.js added
anshsgit Aug 30, 2024
859223e
todoServer.js added
anshsgit Aug 30, 2024
69f081b
todoServerFile.js added
anshsgit Aug 30, 2024
b7dd74b
todos.json added
anshsgit Aug 30, 2024
922954c
package.json added
anshsgit Aug 30, 2024
ff3aad0
package-lock.json added
anshsgit Aug 30, 2024
648b94f
Remove deleted files
anshsgit Aug 30, 2024
11bbed5
readme.md added
anshsgit Aug 30, 2024
3199c62
index.html added
anshsgit Aug 30, 2024
675122e
script.js added
anshsgit Aug 30, 2024
3f0f52c
styles.css added
anshsgit Aug 30, 2024
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 todo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Todo-Application
30 changes: 30 additions & 0 deletions todo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<div class="container1">
<h1>Todo List</h1>
</div>

<div class="container2">
<input type="text" name="" id="todo" placeholder="Enter todo">
<button onclick="addTodo()">Add Todo</button>
</div>


<br> <br>
<div class="container3">
<div id="showTodo"></div>
</div>

</div>

<script src="script.js"></script>
</body>
</html>
33 changes: 33 additions & 0 deletions todo/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function deleteTodo(index) {
const todo = document.getElementById(`container${index}`);
const parent = todo.parentNode;
parent.removeChild(todo);
}

let currentIndex = 0;
function addTodo() {
const inputEl = document.getElementById('todo');

if(inputEl.value === ''){
alert('Please enter a todo.');
return;
}
const todoParent = document.getElementById('showTodo');
const todoChild1 = document.createElement('div');
todoChild1.setAttribute('id', 'container'+currentIndex);
const todoGrandchild1 = document.createElement('p');
const todoGrandchild2 = document.createElement('button');
todoGrandchild2.setAttribute('onclick', 'deleteTodo('+currentIndex+')')

todoChild1.appendChild(todoGrandchild1);
todoChild1.appendChild(todoGrandchild2);

todoParent.appendChild(todoChild1);

todoGrandchild1.innerHTML = inputEl.value.trim();
todoGrandchild2.innerHTML = 'Delete';

inputEl.value = '';
currentIndex++;

}
41 changes: 41 additions & 0 deletions todo/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
body {
font-size: 16px;
}

.container {
display: flex;
justify-content: center;
flex-direction: column;
margin: 10px auto 0px auto;
padding: 25px;
}

.container1 {
display: flex;
justify-content: center;
}

.container2 {
display: flex;
justify-content: center;
}


#showTodo {
padding: 10px;
display: flex;
flex-wrap: wrap;

}

#showTodo div {
background-color: beige;
display: flex;
flex-direction: column;
padding: 5px 10px 10px 10px;
margin-right: 7px;
margin-bottom: 7px;
justify-content: center;
width: 120px;
border-radius: 10px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*/

function wait(n) {
return new Promise((resolve) => {
setTimeout(resolve, n*1000)
})
}

module.exports = wait;
6 changes: 6 additions & 0 deletions week-2/week-2-async-js/hard (promises)/2-sleep-completely.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
*/

function sleep(milliseconds) {
return new Promise((resolve) => {
const start = Date.now();
while(Date.now() <= start+milliseconds) {
resolve();
}
})
}

module.exports = sleep;
17 changes: 13 additions & 4 deletions week-2/week-2-async-js/hard (promises)/3-promise-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
*/

function wait1(t) {

return new Promise((resolve) => {
setTimeout(resolve, t*1000);
})
}

function wait2(t) {

return new Promise((resolve) => {
setTimeout(resolve, t*1000);
})
}

function wait3(t) {

return new Promise((resolve) => {
setTimeout(resolve, t*1000);
})
}

function calculateTime(t1, t2, t3) {

let start = Date.now();
return Promise.all([wait1(t1), wait2(t2), wait3(t3)]).then(() => {
return Date.now()-start;
})
}

module.exports = calculateTime;
23 changes: 19 additions & 4 deletions week-2/week-2-async-js/hard (promises)/4-promise-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,34 @@
*/

function wait1(t) {

return new Promise((resolve) => {
setTimeout(resolve, t*1000);
})
}

function wait2(t) {

return new Promise((resolve) => {
setTimeout(resolve, t*1000);
})
}

function wait3(t) {

return new Promise((resolve) => {
setTimeout(resolve, t*1000);
})
}

function calculateTime(t1, t2, t3) {

let start = Date.now();
return wait1(t1).then(() => {
return wait2(t2);
})
.then(() => {
return wait3(t3);
})
.then(() => {
return Date.now()-start;
})
}

module.exports = calculateTime;
9 changes: 9 additions & 0 deletions week-2/week-2-js/easy/anagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
*/

function isAnagram(str1, str2) {
let newStr1 = str1.toLowerCase().split('').sort().join('');
let newStr2 = str2.toLowerCase().split('').sort().join('');
if(newStr1 === newStr2) {
return true;
}
else {
return false;
}


}

module.exports = isAnagram;
20 changes: 19 additions & 1 deletion week-2/week-2-js/easy/expenditure-analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,25 @@
*/

function calculateTotalSpentByCategory(transactions) {
return [];
let priceTotal = {};
transactions.forEach((transaction) => {
let {category, price} = transaction;
if(priceTotal[category]){
priceTotal[category] += price;
}
else {
priceTotal[category] = price;
}
})

const result = Object.keys(priceTotal).map((category) => {
return {
category,
totalSpent: priceTotal[category]
}
})

return result;
}

module.exports = calculateTotalSpentByCategory;
8 changes: 7 additions & 1 deletion week-2/week-2-js/easy/findLargestElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
*/

function findLargestElement(numbers) {

let max = numbers[0];
for(let i=1; i<numbers.length; i++) {
if(max < numbers[i]){
max = numbers[i];
}
}
return max;
}

module.exports = findLargestElement;
48 changes: 47 additions & 1 deletion week-2/week-2-js/hard/calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,52 @@
Once you've implemented the logic, test your code by running
*/

class Calculator {}

const math = require('mathjs');
class Calculator {
constructor() {
this.result = 0;
}

add(n) {
this.result += n;
}

subtract(n) {
this.result -= n;
}

multiply(n) {
this.result *= n;
}

divide(n) {
if(n !== 0)
this.result /= n;
else
throw new Error("Not defined");

}

clear() {
this.result = 0;
}

getResult() {
return this.result;
}

calculate(expression) {
const trimmedExpression = expression.replace(/\s+/g, '');
try {
this.result = math.evaluate(trimmedExpression);
if(this.result === Infinity || this.result === -Infinity){
throw new Error("Division by zero is not allowed");
}
} catch(error) {
throw new Error(`Invalid expression: ${error.message}`);
}
}
}

module.exports = Calculator;
29 changes: 29 additions & 0 deletions week-2/week-2-js/hard/todo-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,36 @@
*/

class Todo {
constructor() {
this.todos = [];
}

add(todo) {
this.todos.push(todo);
}

remove(indexOfTodo) {
this.todos.splice(indexOfTodo,1);
}

update(index, updatedTodo) {
if(index < this.todos.length)
this.todos[index] = updatedTodo;
}

getAll() {
return this.todos;
}

get(indexOfTodo) {
if(indexOfTodo < this.todos.length)
return this.todos[indexOfTodo];
else return null;
}

clear() {
this.todos = [];
}
}

module.exports = Todo;
6 changes: 6 additions & 0 deletions week-2/week-2-js/medium/countVowels.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

function countVowels(str) {
// Your code here
let newStr = str.toLowerCase().replace(/\s/g, "").split('');
let counter = 0;
newStr.forEach(element => {
if(element==='a' || element==='e' || element==='i' || element==='o' || element==='u') counter++;
});
return counter;
}

module.exports = countVowels;
11 changes: 10 additions & 1 deletion week-2/week-2-js/medium/palindrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
*/

function isPalindrome(str) {
return true;
let newStr = str.toLowerCase().replace(/[\s\W]/g, '');
let strArray = newStr.split('');
const newArray = [];
let leng = strArray.length;
for(let i=0; i<leng; i++) {
newArray.push(strArray[leng-i-1]);
}

if(newArray.join('') === newStr) return true;
else return false;
}

module.exports = isPalindrome;
Loading