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

1week / 0-4 solved #104

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions week-1/problems/0-horizontal-align/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
width: 1200px;
/* margin: 0px auto; */
background-color: red;
height: 500px;
}

.content {
Expand Down
4 changes: 3 additions & 1 deletion week-1/problems/1-vertical-align/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
}
.horizontal-center {
margin: 0 auto;
display: flex;
text-align: center;
}
</style>
</head>
</head>"

<body>
<div class="container">
Expand Down
7 changes: 6 additions & 1 deletion week-1/problems/2-flex-layout/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,25 @@
<link rel="stylesheet" href="./index.css">

<style>

.container {
width: 1200px;
max-width: 1200px;
margin: 0 auto;
display: flex;


}

.left {
background-color: red;
flex-grow: 1;
text-align: center;
}

.right {
background-color: blue;
flex-grow: 2;
text-align: center;
}
</style>
</head>
Expand Down
4 changes: 3 additions & 1 deletion week-1/problems/3-grid-layout/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<title>Grid Layout</title>
<style>
.container {
width: 1200px;
max-width: 1200px;
margin: 0 auto;
display: grid;
grid-template-columns: 1fr 2fr;
Expand All @@ -16,10 +16,12 @@

.left {
background-color: red;
text-align: center;
}

.right {
background-color: blue;
text-align: center;
}
</style>
</head>
Expand Down
6 changes: 5 additions & 1 deletion week-1/problems/4-more-complicated-grid/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<title>Grid Layout</title>
<style>
.container {
width: 1200px;
max-width: 1200px;
margin: 0 auto;
display: grid;
grid-template-columns: 1fr 2fr;
Expand All @@ -17,6 +17,8 @@

.left {
background-color: red;


}

.right {
Expand All @@ -27,9 +29,11 @@
justify-content: center;
align-items: center;
height: 100%;

}
.horizontal-center {
margin: 0 auto;
text-align: center;
}
.grid1 {
display: grid;
Expand Down
7 changes: 7 additions & 0 deletions week-1/problems/5-vscode-bottombar/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
body {
font-family: Arial, sans-serif;
background-color: black;
display: flex;
justify-content: center;
align-items: center;
}
.container {
background-color: black;
Expand All @@ -14,6 +17,10 @@
color: white;
}

.container p {
opacity: 70%;
}

.languagePanel {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
Expand Down
11 changes: 11 additions & 0 deletions week-2/week-2-async-js/easy/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


// setInterval(()=>{console.log("after few seconds");
// },10000)

function count() {
console.log("after one second the fuction called againg");
setTimeout(count,10000)
}

count()
1 change: 1 addition & 0 deletions week-2/week-2-async-js/easy/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I wrote some secrete here!
14 changes: 14 additions & 0 deletions week-2/week-2-async-js/easy/fileWrite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs').promises;

async function writeFile(filename, content) {
try {
await fs.writeFile(filename,content,'utf8')
console.log('successfully write into the file ');

} catch (error) {
console.log('Error during writing file',error);

}
}

writeFile('easy/example.txt','secret has been reveled ! ')
31 changes: 31 additions & 0 deletions week-2/week-2-async-js/easy/files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

const fs = require('fs')

fs.readFile('easy/example.txt', 'utf-8',(err, data)=>{
if (err) {
if (err.code == 'ENOENT') {
console.log("File not found",err);

} else {
console.log("Error during reding",err);

}
return;
}

console.log("File Content : ",data);

});

// expensive operation
function expensiveOperation() {
let sum = 0
for (let i = 0; i < 1e8; i++) {
sum += i;

}
console.log("Expensive operation done");

}

expensiveOperation()
26 changes: 26 additions & 0 deletions week-2/week-2-async-js/medium/clearFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

const fs = require('fs')


function ClearFile(filePath) {
fs.readFile(filePath,'utf8', (err, data)=>{
if (err) {
console.log('Error during reading',err);
return;
}
const cleareddata = data.replace(/\s+/g, ' ').trim()

fs.writeFile(filePath,cleareddata,'utf8',(err)=>{
if (err) {
console.log('Error during writing the file',err);
return;
}
console.log('Writing file successfull');

})

});
}

let filePath = 'medium/example.txt'
ClearFile(filePath)
21 changes: 21 additions & 0 deletions week-2/week-2-async-js/medium/clock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@


function counter() {
const now = new Date()

// 24
const hours24 = now.getHours().toString().padStart(2,'0')
const minutes = now.getMinutes().toString().padStart(2,'0');
const seconds = now.getSeconds().toString().padStart(2,'0')

//12
const hours12 = ((now.getHours()+11)% 12 +1).toString().padStart(2, '0');
const ampm = (now.getHours()>=12) ? 'PM' : 'AM'

console.log(`24-hour formet:${hours24}:${minutes}:${seconds}`);
console.log(`12-hour farmet:${hours12}:${minutes}:${seconds}:${ampm}`);

setTimeout(counter,1000)
}

counter()
1 change: 1 addition & 0 deletions week-2/week-2-async-js/medium/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world my name is raman
12 changes: 12 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,19 @@
*/

function isAnagram(str1, str2) {
if (str1.length !== str2.length) {
return false;
}

function sortStr(str) {
return str.toLowerCase().split('').sort().join()
}

return sortStr(str1)=== sortStr(str2);

}

module.exports = isAnagram;



19 changes: 18 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,24 @@
*/

function calculateTotalSpentByCategory(transactions) {
return [];

const allCategoryMap = {};

transactions.forEach((transaction) => {
const {category, price} = transaction;
if (category in allCategoryMap) {
allCategoryMap[category] += price;
}else {
allCategoryMap[category] = price;
}

});

const result = [];
for (const category in allCategoryMap) {
result.push({category: category, TotalSpents : allCategoryMap[category]});
}
return result;
}

module.exports = calculateTotalSpentByCategory;
9 changes: 8 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,14 @@
*/

function findLargestElement(numbers) {

let largest = numbers[0];
for (let i = 0; i < numbers.length; i++) {

if (largest <numbers[i]) {
largest = numbers[i]
}
}
return largest
}

module.exports = findLargestElement;
56 changes: 55 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,60 @@
Once you've implemented the logic, test your code by running
*/

class Calculator {}
class Calculator {
constructor(){
this.result = 0
}

add(number){
this.result += number
}

subtract(number){
this.result -= number
}

multiply(number){
this.result *= number
}

divide(number){
if (number === 0) {
throw new Error('Invalid Expression: Divide by Zero')
}
this.result /= number
}

clear (){
this.result = 0;
}

getResult(){
return this.result
}


calculate(inputExpression) {
const temp = inputExpression;
const cleanedExpression = temp.replace(/\s+/g,'');
const isValidExpression = /^[0-9+\-*/().]+$/.test(cleanedExpression);

if (!isValidExpression) {
throw new Error("Invalid expression.")
}

try {
this.result = eval(inputExpression)
} catch (error) {
throw new Error("Invalid expression.")
}

if (this.result === Infinity) {
throw new Error("Cannot divide a number by 0.")
}

return this.result
}
}

module.exports = Calculator;
Loading