├── week-6
├── 3-use-ref
│ ├── src
│ │ ├── App.css
│ │ ├── index.css
│ │ ├── main.jsx
│ │ ├── App.jsx
│ │ └── components
│ │ │ ├── Assignment1.jsx
│ │ │ └── Assignment2.jsx
│ ├── vite.config.js
│ ├── .gitignore
│ ├── index.html
│ ├── README.md
│ ├── .eslintrc.cjs
│ ├── package.json
│ └── public
│ │ └── vite.svg
├── 1-use-memo
│ ├── src
│ │ ├── App.css
│ │ ├── index.css
│ │ ├── main.jsx
│ │ ├── App.jsx
│ │ └── components
│ │ │ ├── Assignment1.jsx
│ │ │ ├── Assignment3.jsx
│ │ │ └── Assignment2.jsx
│ ├── vite.config.js
│ ├── .gitignore
│ ├── index.html
│ ├── README.md
│ ├── .eslintrc.cjs
│ ├── package.json
│ └── public
│ │ └── vite.svg
├── 2-use-callback
│ ├── src
│ │ ├── App.css
│ │ ├── index.css
│ │ ├── main.jsx
│ │ ├── App.jsx
│ │ └── components
│ │ │ ├── Assignment1.jsx
│ │ │ └── Assignment2.jsx
│ ├── vite.config.js
│ ├── .gitignore
│ ├── index.html
│ ├── README.md
│ ├── .eslintrc.cjs
│ ├── package.json
│ └── public
│ │ └── vite.svg
├── README.md
└── solutions
│ ├── 1
│ └── components
│ │ ├── Assignment1.jsx
│ │ ├── Assignment3.jsx
│ │ └── Assignment2.jsx
│ ├── 2
│ └── components
│ │ ├── Assignment1.jsx
│ │ └── Assignment2.jsx
│ └── 3
│ └── components
│ ├── Assignment1.jsx
│ └── Assignment2.jsx
├── week-2
├── 02-nodejs
│ ├── todos.json
│ ├── .gitignore
│ ├── files
│ │ └── a.txt
│ ├── package.json
│ ├── fileServer.js
│ ├── README.md
│ ├── solutions
│ │ ├── fileServer.solution.js
│ │ ├── todoServer.solution.file.js
│ │ └── todoServer.solution.js
│ ├── todoServer.js
│ └── tests
│ │ ├── todoServer.test.js
│ │ └── fileServer.test.js
└── 01-async-js
│ ├── .gitignore
│ ├── temp.txt
│ ├── easy
│ ├── 01-counter.js
│ ├── 4-write-to-file.md
│ ├── 02-counter.js
│ ├── 1-counter.md
│ ├── 04-write-to-file.js
│ ├── 3-read-from-file.md
│ ├── 03-read-from-file.js
│ └── 2-counter.md
│ ├── medium
│ ├── 02-clock.js
│ ├── 2-clock.md
│ ├── 1-file-cleaner.md
│ └── 01-file-cleaner.js
│ ├── hard (promises)
│ ├── 1-promisify-setTimeout.js
│ ├── 2-sleep-completely.js
│ ├── 3-promise-all.js
│ └── 4-promise-chain.js
│ ├── package.json
│ ├── tests
│ ├── 4-promise-chain.test.js
│ ├── 3-promise-all.test.js
│ ├── 1-promisify-setTimeout.test.js
│ └── 2-sleep-completely.test.js
│ └── README.md
├── week-3
├── 01-middlewares
│ ├── index.js
│ ├── .gitignore
│ ├── jest.config.ts
│ ├── package.json
│ ├── 01-requestcount.js
│ ├── 03-errorcount.js
│ ├── tests
│ │ ├── 01-requestcount.spec.js
│ │ ├── 03-errorcount.spec.js
│ │ └── 02-ratelimitter.spec.js
│ ├── 02-ratelimitter.js
│ └── tsconfig.json
├── 02-jwt
│ ├── .gitignore
│ ├── package.json
│ ├── index.js
│ ├── tests
│ │ └── index.spec.js
│ ├── tsconfig.json
│ └── package-lock.json
├── 03-mongo
│ ├── .gitignore
│ ├── middleware
│ │ ├── user.js
│ │ └── admin.js
│ ├── index.js
│ ├── package.json
│ ├── routes
│ │ ├── admin.js
│ │ └── user.js
│ ├── db
│ │ └── index.js
│ ├── solution
│ │ ├── middleware
│ │ │ ├── user.js
│ │ │ └── admin.js
│ │ ├── db
│ │ │ └── index.js
│ │ └── routes
│ │ │ ├── admin.js
│ │ │ └── user.js
│ └── README.md
├── 04-mongo-with-jwt-auth
│ ├── .gitignore
│ ├── middleware
│ │ ├── user.js
│ │ └── admin.js
│ ├── index.js
│ ├── package.json
│ ├── routes
│ │ ├── admin.js
│ │ └── user.js
│ ├── db
│ │ └── index.js
│ ├── solution
│ │ ├── middleware
│ │ │ ├── user.js
│ │ │ └── admin.js
│ │ ├── routes
│ │ │ ├── user.js
│ │ │ └── admin.js
│ │ └── db
│ │ │ └── index.js
│ └── README.md
├── solutions
│ ├── 01-requestcount.js
│ ├── 03-errorcount.js
│ ├── 02.js
│ └── 02-ratelimitter.js
└── README.md
├── week-5
├── level-1
│ ├── BusinessCard.png
│ └── README.md
└── solutions
│ └── level-1
│ └── BusinessCard.jsx
├── 01-js
├── package-lock.json
├── package.json
├── easy
│ ├── findLargestElement.js
│ ├── anagram.js
│ └── expenditure-analysis.js
├── medium
│ ├── palindrome.js
│ ├── countVowels.js
│ └── times.js
├── README.md
├── tests
│ ├── findLargestElement.test.js
│ ├── anagram.test.js
│ ├── countVowels.test.js
│ ├── palindrome.test.js
│ ├── todo-list.test.js
│ ├── expenditure-analysis.test.js
│ └── calculator.test.js
└── hard
│ ├── todo-list.js
│ └── calculator.js
├── week-1
└── offline-class-1
│ ├── level-2
│ ├── 01-Class.js
│ ├── 03-JSON.js
│ ├── 05-Object.js
│ ├── 04-Math.js
│ └── 02-Date.js
│ └── level-1
│ ├── 02-Number.js
│ ├── 01-String.js
│ └── 03-Array.js
└── week-4
├── react-basics
└── README.md
├── README.md
└── index.html
/week-6/3-use-ref/src/App.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/week-2/02-nodejs/todos.json:
--------------------------------------------------------------------------------
1 | []
--------------------------------------------------------------------------------
/week-3/01-middlewares/index.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/week-6/1-use-memo/src/App.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/week-6/1-use-memo/src/index.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/week-6/2-use-callback/src/App.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/week-6/3-use-ref/src/index.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/week-6/2-use-callback/src/index.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/week-3/02-jwt/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/week-3/03-mongo/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/week-2/02-nodejs/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/week-2/02-nodejs/files/a.txt:
--------------------------------------------------------------------------------
1 | hello from a.txt
--------------------------------------------------------------------------------
/week-3/01-middlewares/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/week-2/01-async-js/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | solutions
--------------------------------------------------------------------------------
/week-2/01-async-js/temp.txt:
--------------------------------------------------------------------------------
1 | this is the new line i added
--------------------------------------------------------------------------------
/week-3/04-mongo-with-jwt-auth/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/week-5/level-1/BusinessCard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshDev56/100xDevs_MERN_assignments/HEAD/week-5/level-1/BusinessCard.png
--------------------------------------------------------------------------------
/week-2/01-async-js/easy/01-counter.js:
--------------------------------------------------------------------------------
1 | function counter(counter) {
2 | setInterval(() => {
3 | console.log(counter++);
4 | }, 1000);
5 | }
6 |
7 | counter(1);
--------------------------------------------------------------------------------
/week-3/01-middlewares/jest.config.ts:
--------------------------------------------------------------------------------
1 | export default {
2 | clearMocks: true,
3 | collectCoverage: true,
4 | coverageDirectory: 'coverage',
5 | coverageProvider: 'v8',
6 | };
7 |
8 |
--------------------------------------------------------------------------------
/week-2/01-async-js/easy/4-write-to-file.md:
--------------------------------------------------------------------------------
1 | ## Write to a file
2 | Using the fs library again, try to write to the contents of a file.
3 | You can use the fs library to as a black box, the goal is to understand async tasks.
--------------------------------------------------------------------------------
/week-6/1-use-memo/vite.config.js:
--------------------------------------------------------------------------------
1 | import { defineConfig } from 'vite'
2 | import react from '@vitejs/plugin-react'
3 |
4 | // https://vitejs.dev/config/
5 | export default defineConfig({
6 | plugins: [react()],
7 | })
8 |
--------------------------------------------------------------------------------
/week-6/3-use-ref/vite.config.js:
--------------------------------------------------------------------------------
1 | import { defineConfig } from 'vite'
2 | import react from '@vitejs/plugin-react'
3 |
4 | // https://vitejs.dev/config/
5 | export default defineConfig({
6 | plugins: [react()],
7 | })
8 |
--------------------------------------------------------------------------------
/week-6/2-use-callback/vite.config.js:
--------------------------------------------------------------------------------
1 | import { defineConfig } from 'vite'
2 | import react from '@vitejs/plugin-react'
3 |
4 | // https://vitejs.dev/config/
5 | export default defineConfig({
6 | plugins: [react()],
7 | })
8 |
--------------------------------------------------------------------------------
/week-2/01-async-js/easy/02-counter.js:
--------------------------------------------------------------------------------
1 | function countWithoutInterval(count) {
2 | setTimeout(() => {
3 | console.log(count++);
4 | countWithoutInterval(count);
5 | }, 1000);
6 | }
7 |
8 | countWithoutInterval(1)
--------------------------------------------------------------------------------
/week-2/01-async-js/easy/1-counter.md:
--------------------------------------------------------------------------------
1 | ## Create a counter in JavaScript
2 |
3 | We have already covered this in the second lesson, but as an easy recap try to code a counter in Javascript
4 | It should go up as time goes by in intervals of 1 second
--------------------------------------------------------------------------------
/01-js/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "01",
3 | "version": "1.0.0",
4 | "lockfileVersion": 2,
5 | "requires": true,
6 | "packages": {
7 | "": {
8 | "name": "01",
9 | "version": "1.0.0",
10 | "license": "ISC"
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/week-1/offline-class-1/level-2/01-Class.js:
--------------------------------------------------------------------------------
1 |
2 | class Animal {
3 | constructor(name, legCount) {
4 | this.name = name
5 | this.legCount = legCount
6 | }
7 | describe() {
8 | return `${this.name} has ${this.legCount} legs`
9 | }
10 | }
11 |
12 |
13 |
--------------------------------------------------------------------------------
/week-3/03-mongo/middleware/user.js:
--------------------------------------------------------------------------------
1 | function userMiddleware(req, res, next) {
2 | // Implement user auth logic
3 | // You need to check the headers and validate the user from the user DB. Check readme for the exact headers to be expected
4 | }
5 |
6 | module.exports = userMiddleware;
--------------------------------------------------------------------------------
/week-3/04-mongo-with-jwt-auth/middleware/user.js:
--------------------------------------------------------------------------------
1 | function userMiddleware(req, res, next) {
2 | // Implement user auth logic
3 | // You need to check the headers and validate the user from the user DB. Check readme for the exact headers to be expected
4 | }
5 |
6 | module.exports = userMiddleware;
--------------------------------------------------------------------------------
/week-2/01-async-js/easy/04-write-to-file.js:
--------------------------------------------------------------------------------
1 | const fs = require('fs');
2 |
3 | let data = " this is the new line i added ";
4 | fs.writeFile("../temp.txt", data, (err) => {
5 | if (err) {
6 | console.log(err);
7 | } else {
8 | console.log("Success");
9 | }
10 | })
--------------------------------------------------------------------------------
/week-6/1-use-memo/src/main.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom/client'
3 | import App from './App.jsx'
4 | import './index.css'
5 |
6 | ReactDOM.createRoot(document.getElementById('root')).render(
7 |
8 |
9 | ,
10 | )
11 |
--------------------------------------------------------------------------------
/week-6/3-use-ref/src/main.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom/client'
3 | import App from './App.jsx'
4 | import './index.css'
5 |
6 | ReactDOM.createRoot(document.getElementById('root')).render(
7 |
8 |
9 | ,
10 | )
11 |
--------------------------------------------------------------------------------
/week-6/2-use-callback/src/main.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom/client'
3 | import App from './App.jsx'
4 | import './index.css'
5 |
6 | ReactDOM.createRoot(document.getElementById('root')).render(
7 |
8 |
9 | ,
10 | )
11 |
--------------------------------------------------------------------------------
/week-3/03-mongo/middleware/admin.js:
--------------------------------------------------------------------------------
1 | // Middleware for handling auth
2 | function adminMiddleware(req, res, next) {
3 | // Implement admin auth logic
4 | // You need to check the headers and validate the admin from the admin DB. Check readme for the exact headers to be expected
5 | }
6 |
7 | module.exports = adminMiddleware;
--------------------------------------------------------------------------------
/week-2/01-async-js/medium/02-clock.js:
--------------------------------------------------------------------------------
1 | function clock() {
2 | setInterval(() => {
3 | let date = new Date();
4 | let hour = date.getHours();
5 | // HH:MM::SS AM/PM
6 | console.log(hour + ":" + date.getMinutes() + ":" + date.getSeconds(), hour > 12 ? "PM" : "AM");
7 | }, 1000)
8 | }
9 |
10 | clock()
--------------------------------------------------------------------------------
/week-3/04-mongo-with-jwt-auth/middleware/admin.js:
--------------------------------------------------------------------------------
1 | // Middleware for handling auth
2 | function adminMiddleware(req, res, next) {
3 | // Implement admin auth logic
4 | // You need to check the headers and validate the admin from the admin DB. Check readme for the exact headers to be expected
5 | }
6 |
7 | module.exports = adminMiddleware;
--------------------------------------------------------------------------------
/week-2/01-async-js/medium/2-clock.md:
--------------------------------------------------------------------------------
1 | Using `1-counter.md` or `2-counter.md` from the easy section, can you create a
2 | clock that shows you the current machine time?
3 |
4 | Can you make it so that it updates every second, and shows time in the following formats -
5 |
6 | - HH:MM::SS (Eg. 13:45:23)
7 |
8 | - HH:MM::SS AM/PM (Eg 01:45:23 PM)
9 |
--------------------------------------------------------------------------------
/week-6/3-use-ref/src/App.jsx:
--------------------------------------------------------------------------------
1 | import './App.css'
2 | import { Assignment1 } from './components/Assignment1'
3 | import { Assignment2 } from './components/Assignment2'
4 |
5 | function App() {
6 | return (
7 | <>
8 |
9 | {/* */}
10 | >
11 | )
12 | }
13 |
14 | export default App
15 |
--------------------------------------------------------------------------------
/week-6/2-use-callback/src/App.jsx:
--------------------------------------------------------------------------------
1 | import './App.css'
2 | import { Assignment1 } from './components/Assignment1'
3 | import { Assignment2 } from './components/Assignment2'
4 |
5 | function App() {
6 | return (
7 | <>
8 | {/* */}
9 |
10 | >
11 | )
12 | }
13 |
14 | export default App
15 |
--------------------------------------------------------------------------------
/week-6/README.md:
--------------------------------------------------------------------------------
1 | ## React hook assignments
2 | You will find a bunch of folders this week, each with some set of assignments for a specific hook
3 | Go to the folder (for example 1-use-memo) and comment out the Assignment component you are working on (Assignment1/Assignment2...) and try to solve it
4 | There are no tests, but solution videos will be provided
--------------------------------------------------------------------------------
/week-2/01-async-js/medium/1-file-cleaner.md:
--------------------------------------------------------------------------------
1 | ## File cleaner
2 | Read a file, remove all the extra spaces and write it back to the same file.
3 |
4 | For example, if the file input was
5 | ```
6 | hello world my name is raman
7 | ```
8 |
9 | After the program runs, the output should be
10 |
11 | ```
12 | hello world my name is raman
13 | ```
--------------------------------------------------------------------------------
/week-3/02-jwt/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "02-jwt",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "jsonwebtoken": "^9.0.2",
14 | "zod": "^3.22.4"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/week-6/1-use-memo/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.local
14 |
15 | # Editor directories and files
16 | .vscode/*
17 | !.vscode/extensions.json
18 | .idea
19 | .DS_Store
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw?
25 |
--------------------------------------------------------------------------------
/week-6/3-use-ref/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.local
14 |
15 | # Editor directories and files
16 | .vscode/*
17 | !.vscode/extensions.json
18 | .idea
19 | .DS_Store
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw?
25 |
--------------------------------------------------------------------------------
/week-6/2-use-callback/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.local
14 |
15 | # Editor directories and files
16 | .vscode/*
17 | !.vscode/extensions.json
18 | .idea
19 | .DS_Store
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw?
25 |
--------------------------------------------------------------------------------
/week-2/01-async-js/easy/3-read-from-file.md:
--------------------------------------------------------------------------------
1 | ## Reading the contents of a file
2 |
3 | Write code to read contents of a file and print it to the console.
4 | You can use the fs library to as a black box, the goal is to understand async tasks.
5 | Try to do an expensive operation below the file read and see how it affects the output.
6 | Make the expensive operation more and more expensive and see how it affects the output.
7 |
8 |
--------------------------------------------------------------------------------
/week-6/1-use-memo/src/App.jsx:
--------------------------------------------------------------------------------
1 | import './App.css'
2 | import { Assignment1 } from './components/Assignment1'
3 | import { Assignment2 } from './components/Assignment2'
4 | import { Assignment3 } from './components/Assignment3'
5 |
6 | function App() {
7 | return (
8 | <>
9 |
10 | {/* */}
11 | {/* */}
12 | >
13 | )
14 | }
15 |
16 | export default App
17 |
--------------------------------------------------------------------------------
/week-2/01-async-js/easy/03-read-from-file.js:
--------------------------------------------------------------------------------
1 | const fs = require('fs');
2 |
3 | fs.readFile("../temp.txt", "utf-8", (err, data) => {
4 | if (err) {
5 | console.log("Something wrong " + err.message);
6 | } else {
7 | console.log(data);
8 | }
9 | })
10 |
11 | // expensive operation
12 | let counter = 0;
13 | for (let index = 0; index < 1000000000; index++) {
14 | counter++;
15 | }
16 |
17 | console.log(counter);
--------------------------------------------------------------------------------
/week-2/01-async-js/hard (promises)/1-promisify-setTimeout.js:
--------------------------------------------------------------------------------
1 | /*
2 | Write a function that returns a promise that resolves after n seconds have passed, where n is passed as an argument to the function.
3 | */
4 |
5 | function wait(n) {
6 | return new Promise((resolve, reject) => {
7 |
8 | setTimeout(() => {
9 | resolve()
10 | }, n * 1000);
11 |
12 | })
13 |
14 | }
15 |
16 | module.exports = wait;
17 |
--------------------------------------------------------------------------------
/week-6/1-use-memo/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Vite + React
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/week-6/3-use-ref/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Vite + React
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/week-6/2-use-callback/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Vite + React
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/week-6/1-use-memo/README.md:
--------------------------------------------------------------------------------
1 | # React + Vite
2 |
3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4 |
5 | Currently, two official plugins are available:
6 |
7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9 |
--------------------------------------------------------------------------------
/week-6/3-use-ref/README.md:
--------------------------------------------------------------------------------
1 | # React + Vite
2 |
3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4 |
5 | Currently, two official plugins are available:
6 |
7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9 |
--------------------------------------------------------------------------------
/week-6/2-use-callback/README.md:
--------------------------------------------------------------------------------
1 | # React + Vite
2 |
3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4 |
5 | Currently, two official plugins are available:
6 |
7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9 |
--------------------------------------------------------------------------------
/week-3/03-mongo/index.js:
--------------------------------------------------------------------------------
1 | const express = require('express');
2 | const bodyParser = require('body-parser');
3 | const app = express();
4 | const adminRouter = require("./routes/admin")
5 | const userRouter = require("./routes/user");
6 |
7 | // Middleware for parsing request bodies
8 | app.use(bodyParser.json());
9 | app.use("/admin", adminRouter)
10 | app.use("/user", userRouter)
11 |
12 | const PORT = 3000;
13 |
14 | app.listen(PORT, () => {
15 | console.log(`Server is running on port ${PORT}`);
16 | });
17 |
--------------------------------------------------------------------------------
/01-js/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "01",
3 | "version": "1.0.0",
4 | "description": "You are provided empty JavaScript files (or having function signatures) in this directory. You have to follow the instructions given in each file and write the code in the same file to complete the assignment.",
5 | "main": "anagram.js",
6 | "directories": {
7 | "test": "tests"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "devDependencies": {
13 | "jest": "^29.7.0"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/week-3/04-mongo-with-jwt-auth/index.js:
--------------------------------------------------------------------------------
1 | const express = require('express');
2 | const bodyParser = require('body-parser');
3 | const app = express();
4 | const adminRouter = require("./routes/admin")
5 | const userRouter = require("./routes/user");
6 |
7 | // Middleware for parsing request bodies
8 | app.use(bodyParser.json());
9 | app.use("/admin", adminRouter)
10 | app.use("/user", userRouter)
11 |
12 | const PORT = 3000;
13 | app.listen(PORT, () => {
14 | console.log(`Server is running on port ${PORT}`);
15 | });
16 |
--------------------------------------------------------------------------------
/01-js/easy/findLargestElement.js:
--------------------------------------------------------------------------------
1 | /*
2 | Write a function `findLargestElement` that takes an array of numbers and returns the largest element.
3 | Example:
4 | - Input: [3, 7, 2, 9, 1]
5 | - Output: 9
6 | */
7 |
8 | function findLargestElement(numbers) {
9 | let max = numbers[0];
10 | for (let index = 1; index < numbers.length; index++) {
11 | if (numbers[index] > max) {
12 | max = numbers[index];
13 | }
14 | }
15 | return max;
16 | }
17 |
18 | module.exports = findLargestElement;
--------------------------------------------------------------------------------
/week-3/03-mongo/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "03-mongo",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "@babel/plugin-transform-modules-commonjs": "^7.23.3",
14 | "express": "^4.18.2",
15 | "jest": "^29.7.0",
16 | "mongoose": "^8.0.3",
17 | "supertest": "^6.3.3",
18 | "ts-node": "^10.9.2"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/week-2/01-async-js/hard (promises)/2-sleep-completely.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Write a function that halts the JS thread (make it busy wait) for a given number of milliseconds.
3 | * During this time the thread should not be able to do anything else.
4 | * the function should return a promise just like before
5 | */
6 |
7 | function sleep(milliseconds) {
8 | let time = new Date().getTime();
9 | while (new Date().getTime() - time < milliseconds) { }
10 | return new Promise((resolve) => { resolve() });
11 | }
12 |
13 | module.exports = sleep;
14 |
--------------------------------------------------------------------------------
/week-3/03-mongo/routes/admin.js:
--------------------------------------------------------------------------------
1 | const { Router } = require("express");
2 | const adminMiddleware = require("../middleware/admin");
3 | const router = Router();
4 |
5 | // Admin Routes
6 | router.post('/signup', (req, res) => {
7 | // Implement admin signup logic
8 | });
9 |
10 | router.post('/courses', adminMiddleware, (req, res) => {
11 | // Implement course creation logic
12 | });
13 |
14 | router.get('/courses', adminMiddleware, (req, res) => {
15 | // Implement fetching all courses logic
16 | });
17 |
18 | module.exports = router;
--------------------------------------------------------------------------------
/week-2/01-async-js/medium/01-file-cleaner.js:
--------------------------------------------------------------------------------
1 | const fs = require('fs');
2 |
3 | fs.readFile("../temp.txt", "utf-8", (error, data) => {
4 | if (error) {
5 | console.log(error.message);
6 | } else {
7 | data = data.replace(/\s+/g, " ")
8 | writeNewStr(data);
9 | }
10 | })
11 |
12 |
13 | function writeNewStr(data) {
14 | fs.writeFile("../temp.txt", data, (error) => {
15 | if (error) {
16 | console.log(error);
17 | } else {
18 | console.log("Sucesss");
19 | }
20 | })
21 | }
--------------------------------------------------------------------------------
/week-3/04-mongo-with-jwt-auth/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "03-mongo",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "@babel/plugin-transform-modules-commonjs": "^7.23.3",
14 | "express": "^4.18.2",
15 | "jest": "^29.7.0",
16 | "mongoose": "^8.0.3",
17 | "supertest": "^6.3.3",
18 | "ts-node": "^10.9.2"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/week-3/01-middlewares/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "01-middlewares",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "express": "^4.18.2",
14 | "jest": "^29.7.0",
15 | "supertest": "^6.3.3"
16 | },
17 | "devDependencies": {
18 | "@babel/plugin-transform-modules-commonjs": "^7.23.3",
19 | "eslint-plugin-jest": "^27.6.0",
20 | "ts-node": "^10.9.2"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/week-2/01-async-js/easy/2-counter.md:
--------------------------------------------------------------------------------
1 | ## Counter without setInterval
2 |
3 | Without using setInterval, try to code a counter in Javascript. There is a hint at the bottom of the file if you get stuck.
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | (Hint: setTimeout)
--------------------------------------------------------------------------------
/week-6/1-use-memo/.eslintrc.cjs:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | env: { browser: true, es2020: true },
4 | extends: [
5 | 'eslint:recommended',
6 | 'plugin:react/recommended',
7 | 'plugin:react/jsx-runtime',
8 | 'plugin:react-hooks/recommended',
9 | ],
10 | ignorePatterns: ['dist', '.eslintrc.cjs'],
11 | parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
12 | settings: { react: { version: '18.2' } },
13 | plugins: ['react-refresh'],
14 | rules: {
15 | 'react-refresh/only-export-components': [
16 | 'warn',
17 | { allowConstantExport: true },
18 | ],
19 | },
20 | }
21 |
--------------------------------------------------------------------------------
/week-6/3-use-ref/.eslintrc.cjs:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | env: { browser: true, es2020: true },
4 | extends: [
5 | 'eslint:recommended',
6 | 'plugin:react/recommended',
7 | 'plugin:react/jsx-runtime',
8 | 'plugin:react-hooks/recommended',
9 | ],
10 | ignorePatterns: ['dist', '.eslintrc.cjs'],
11 | parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
12 | settings: { react: { version: '18.2' } },
13 | plugins: ['react-refresh'],
14 | rules: {
15 | 'react-refresh/only-export-components': [
16 | 'warn',
17 | { allowConstantExport: true },
18 | ],
19 | },
20 | }
21 |
--------------------------------------------------------------------------------
/week-6/3-use-ref/src/components/Assignment1.jsx:
--------------------------------------------------------------------------------
1 | import { useEffect } from "react";
2 |
3 | // Create a component with a text input field and a button. When the component mounts or the button is clicked, automatically focus the text input field using useRef.
4 |
5 | export function Assignment1() {
6 |
7 | useEffect(() => {
8 |
9 | }, []);
10 |
11 | const handleButtonClick = () => {
12 |
13 | };
14 |
15 | return (
16 |
17 |
18 |
19 |
20 | );
21 | };
22 |
--------------------------------------------------------------------------------
/week-6/2-use-callback/.eslintrc.cjs:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | env: { browser: true, es2020: true },
4 | extends: [
5 | 'eslint:recommended',
6 | 'plugin:react/recommended',
7 | 'plugin:react/jsx-runtime',
8 | 'plugin:react-hooks/recommended',
9 | ],
10 | ignorePatterns: ['dist', '.eslintrc.cjs'],
11 | parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
12 | settings: { react: { version: '18.2' } },
13 | plugins: ['react-refresh'],
14 | rules: {
15 | 'react-refresh/only-export-components': [
16 | 'warn',
17 | { allowConstantExport: true },
18 | ],
19 | },
20 | }
21 |
--------------------------------------------------------------------------------
/week-1/offline-class-1/level-1/02-Number.js:
--------------------------------------------------------------------------------
1 | function explainParseInt(value) {
2 | console.log("Original Value:", value);
3 | let result = parseInt(value);
4 | console.log("After parseInt:", result);
5 | }
6 |
7 | // Example Usage for parseInt
8 | explainParseInt("42");
9 | explainParseInt("42px");
10 | explainParseInt("3.14");
11 |
12 | function explainParseFloat(value) {
13 | console.log("Original Value:", value);
14 | let result = parseFloat(value);
15 | console.log("After parseFloat:", result);
16 | }
17 |
18 | // Example Usage for parseFloat
19 | explainParseFloat("3.14");
20 | explainParseFloat("42");
21 | explainParseFloat("42px");
22 |
--------------------------------------------------------------------------------
/week-3/04-mongo-with-jwt-auth/routes/admin.js:
--------------------------------------------------------------------------------
1 | const { Router } = require("express");
2 | const adminMiddleware = require("../middleware/admin");
3 | const router = Router();
4 |
5 | // Admin Routes
6 | router.post('/signup', (req, res) => {
7 | // Implement admin signup logic
8 | });
9 |
10 | router.post('/signin', (req, res) => {
11 | // Implement admin signup logic
12 | });
13 |
14 | router.post('/courses', adminMiddleware, (req, res) => {
15 | // Implement course creation logic
16 | });
17 |
18 | router.get('/courses', adminMiddleware, (req, res) => {
19 | // Implement fetching all courses logic
20 | });
21 |
22 | module.exports = router;
--------------------------------------------------------------------------------
/week-4/react-basics/README.md:
--------------------------------------------------------------------------------
1 | Try to bootstrap a basic React application using vite.
2 | Read more about vite here - https://vitejs.dev/
3 |
4 | Create the following functionality -
5 | - A basic TODO application where there are two input (title and description) boxes and users can add append TODOs to a div
6 | - Try using the same DOM functionality we did in week 4. Don't try to use state variables in React just yet
7 | - Just tro to port over our original HTML/JS impelementation over to a React project
8 | - Hard todo - If you can, try using `useState` that we discussed this week and propogate the TODOs using state (If you don't understand this, dont worry about it)
--------------------------------------------------------------------------------
/week-3/03-mongo/routes/user.js:
--------------------------------------------------------------------------------
1 | const { Router } = require("express");
2 | const router = Router();
3 | const userMiddleware = require("../middleware/user");
4 |
5 | // User Routes
6 | router.post('/signup', (req, res) => {
7 | // Implement user signup logic
8 | });
9 |
10 | router.get('/courses', (req, res) => {
11 | // Implement listing all courses logic
12 | });
13 |
14 | router.post('/courses/:courseId', userMiddleware, (req, res) => {
15 | // Implement course purchase logic
16 | });
17 |
18 | router.get('/purchasedCourses', userMiddleware, (req, res) => {
19 | // Implement fetching purchased courses logic
20 | });
21 |
22 | module.exports = router
--------------------------------------------------------------------------------
/week-1/offline-class-1/level-2/03-JSON.js:
--------------------------------------------------------------------------------
1 | function jsonMethods(jsonString) {
2 | console.log("Original JSON String:", jsonString);
3 |
4 | // Parsing JSON string to JavaScript object
5 | let parsedObject = JSON.parse(jsonString);
6 | console.log("After JSON.parse():", parsedObject);
7 |
8 | // Stringifying JavaScript object to JSON string
9 | let jsonStringified = JSON.stringify(parsedObject);
10 | console.log("After JSON.stringify():", jsonStringified);
11 | }
12 |
13 | // Example Usage for JSON Methods
14 | const sampleJSONString =
15 | '{"key": "value", "number": 42, "nested": {"nestedKey": "nestedValue"}}';
16 |
17 | jsonMethods(sampleJSONString);
18 |
--------------------------------------------------------------------------------
/01-js/easy/anagram.js:
--------------------------------------------------------------------------------
1 | /*
2 | Write a function `isAnagram` which takes 2 parameters and returns true/false if those are anagrams or not.
3 | What's Anagram?
4 | - A word, phrase, or name formed by rearranging the letters of another, such as spar, formed from rasp.
5 | */
6 |
7 | function isAnagram(str1, str2) {
8 | str1 = sortString(str1.toLowerCase());
9 | str2 = sortString(str2.toLowerCase());
10 | if (str1 === str2) {
11 | return true;
12 | }
13 | return false;
14 | }
15 |
16 | function sortString(str) {
17 | let charArray = str.split('')
18 | charArray.sort();
19 | let ans = charArray.join('')
20 | return ans;
21 | }
22 |
23 | module.exports = isAnagram;
24 |
--------------------------------------------------------------------------------
/week-3/03-mongo/db/index.js:
--------------------------------------------------------------------------------
1 | const mongoose = require('mongoose');
2 |
3 | // Connect to MongoDB
4 | mongoose.connect('your-mongodb-url');
5 |
6 | // Define schemas
7 | const AdminSchema = new mongoose.Schema({
8 | // Schema definition here
9 | });
10 |
11 | const UserSchema = new mongoose.Schema({
12 | // Schema definition here
13 | });
14 |
15 | const CourseSchema = new mongoose.Schema({
16 | // Schema definition here
17 | });
18 |
19 | const Admin = mongoose.model('Admin', AdminSchema);
20 | const User = mongoose.model('User', UserSchema);
21 | const Course = mongoose.model('Course', CourseSchema);
22 |
23 | module.exports = {
24 | Admin,
25 | User,
26 | Course
27 | }
--------------------------------------------------------------------------------
/week-2/01-async-js/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "01-async",
3 | "version": "1.0.0",
4 | "description": "This folder contains assignments related to asynchronous JavaScript.",
5 | "main": "index.js",
6 | "scripts": {
7 | "1-promisify-setTimeout": "npx jest ./tests/1-promisify-setTimeout.test.js",
8 | "2-sleep-completely": "npx jest ./tests/2-sleep-completely.test.js",
9 | "3-promise-all": "npx jest ./tests/3-promise-all.test.js",
10 | "4-promise-chain": "npx jest ./tests/4-promise-chain.test.js",
11 | "all": "npx jest ./tests/"
12 | },
13 | "keywords": [],
14 | "author": "",
15 | "license": "ISC",
16 | "dependencies": {
17 | "jest": "^29.7.0"
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/week-3/04-mongo-with-jwt-auth/db/index.js:
--------------------------------------------------------------------------------
1 | const mongoose = require('mongoose');
2 |
3 | // Connect to MongoDB
4 | mongoose.connect('your-mongodb-url');
5 |
6 | // Define schemas
7 | const AdminSchema = new mongoose.Schema({
8 | // Schema definition here
9 | });
10 |
11 | const UserSchema = new mongoose.Schema({
12 | // Schema definition here
13 | });
14 |
15 | const CourseSchema = new mongoose.Schema({
16 | // Schema definition here
17 | });
18 |
19 | const Admin = mongoose.model('Admin', AdminSchema);
20 | const User = mongoose.model('User', UserSchema);
21 | const Course = mongoose.model('Course', CourseSchema);
22 |
23 | module.exports = {
24 | Admin,
25 | User,
26 | Course
27 | }
--------------------------------------------------------------------------------
/week-3/04-mongo-with-jwt-auth/solution/middleware/user.js:
--------------------------------------------------------------------------------
1 | const {JWT_SECRET} = require("../config");
2 | const jwt = require("jsonwebtoken");
3 |
4 | function userMiddleware(req, res, next) {
5 | const token = req.headers.authorization;
6 | const words = token.split(" ");
7 | const jwtToken = words[1];
8 | const decodedValue = jwt.verify(jwtToken, JWT_SECRET);
9 |
10 | if (decodedValue.username) {
11 | req.username = decodedValue.username;
12 | req.randomData = "Adsadsadsadssd";
13 | next();
14 | } else {
15 | res.status(403).json({
16 | msg: "You are not authenticated"
17 | })
18 | }
19 | }
20 |
21 | module.exports = userMiddleware;
--------------------------------------------------------------------------------
/week-2/02-nodejs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "02-nodejs",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1",
8 | "test-fileServer": "./node_modules/jest/bin/jest.js ./tests/fileServer.test.js",
9 | "test-todoServer": "./node_modules/jest/bin/jest.js ./tests/todoServer.test.js"
10 | },
11 | "keywords": [],
12 | "author": "",
13 | "license": "ISC",
14 | "devDependencies": {
15 | "jest": "^29.5.0",
16 | "supertest": "^6.3.3"
17 | },
18 | "jest": {
19 | "testTimeout": 10000
20 | },
21 | "dependencies": {
22 | "express": "^4.18.2",
23 | "uuid": "^9.0.0"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/week-6/3-use-ref/src/components/Assignment2.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState, useCallback } from 'react';
2 |
3 | // Create a component that tracks and displays the number of times it has been rendered. Use useRef to create a variable that persists across renders without causing additional renders when it changes.
4 |
5 | export function Assignment2() {
6 | const [, forceRender] = useState(0);
7 |
8 | const handleReRender = () => {
9 | // Update state to force re-render
10 | forceRender(Math.random());
11 | };
12 |
13 | return (
14 |
15 |
This component has rendered {0} times.
16 |
17 |
18 | );
19 | };
--------------------------------------------------------------------------------
/week-3/04-mongo-with-jwt-auth/routes/user.js:
--------------------------------------------------------------------------------
1 | const { Router } = require("express");
2 | const router = Router();
3 | const userMiddleware = require("../middleware/user");
4 |
5 | // User Routes
6 | router.post('/signup', (req, res) => {
7 | // Implement user signup logic
8 | });
9 |
10 | router.post('/signin', (req, res) => {
11 | // Implement admin signup logic
12 | });
13 |
14 | router.get('/courses', (req, res) => {
15 | // Implement listing all courses logic
16 | });
17 |
18 | router.post('/courses/:courseId', userMiddleware, (req, res) => {
19 | // Implement course purchase logic
20 | });
21 |
22 | router.get('/purchasedCourses', userMiddleware, (req, res) => {
23 | // Implement fetching purchased courses logic
24 | });
25 |
26 | module.exports = router
--------------------------------------------------------------------------------
/week-5/level-1/README.md:
--------------------------------------------------------------------------------
1 | You have to create a simple React App which has a reusable Card Component which has the following
2 | - Ability to pass in props to the Component
3 | - The Card must show a person's
4 | - Name
5 | - A short description
6 | - LinkedIn, Twitter and other Social Media Handle buttons
7 | - Interests Section
8 | - You can assume that this is kind of an e-business card and feel free to put in your creativity
9 | - Additional & Slightly advanced:
10 | - Create a page where you can add these kind of Cards by taking input from the user
11 | - Create a backend server where these cards get stored in a DB and can handle basic CRUD operations
12 | - Give the feature to perform CRUD operations from the frontend (Can be restricted to the admin only as well)
--------------------------------------------------------------------------------
/week-6/solutions/3/components/Assignment1.jsx:
--------------------------------------------------------------------------------
1 | import { useRef } from "react";
2 | import { useEffect } from "react";
3 |
4 | // Create a component with a text input field and a button. When the component mounts or the button is clicked, automatically focus the text input field using useRef.
5 |
6 | export function Assignment1() {
7 | const inputRef = useRef();
8 |
9 | useEffect(() => {
10 | inputRef.current.focus()
11 | }, [inputRef]);
12 |
13 | const handleButtonClick = () => {
14 | inputRef.current.focus()
15 | };
16 |
17 | return (
18 |
This component has rendered {numberOfTimesReRendered.current} times.
21 |
22 |
23 | );
24 | };
--------------------------------------------------------------------------------
/01-js/README.md:
--------------------------------------------------------------------------------
1 | ## JavaScript Assignments
2 |
3 | You are provided empty JavaScript files (or having function signatures) in this directory.
4 | You have to follow the instructions given in each file and write the code in the same file to complete the assignment.
5 |
6 | ### Assignments
7 | Feel free to start doing these in any order you like.
8 | 1. Easy
9 | 2. Medium
10 | 3. Hard
11 |
12 | ## Testing
13 | 1. Follow the comment above each problem to run test for that problem
14 | 3. To tests for all the problems of this week run ```npx jest ./tests/```
15 |
16 | #### Development Setup
17 | 1. If you have Node.js locally, you should run these on your machine
18 | 2. If you don't, you can copy these over to repl.it and run it there. Tests wont be automated there so you will have to make use judgement to ensure if your code is correct
19 |
--------------------------------------------------------------------------------
/01-js/medium/countVowels.js:
--------------------------------------------------------------------------------
1 | /*
2 | Implement a function `countVowels` that takes a string as an argument and returns the number of vowels in the string.
3 | Note: Consider both uppercase and lowercase vowels ('a', 'e', 'i', 'o', 'u').
4 |
5 | Once you've implemented the logic, test your code by running
6 | */
7 |
8 | function countVowels(str) {
9 | // Your code here
10 | let count = 0;
11 | str = str.toLowerCase();
12 | let hashSet = new Set();
13 |
14 | // Adding elements to the HashSet
15 | hashSet.add("a");
16 | hashSet.add("e");
17 | hashSet.add("i");
18 | hashSet.add("o");
19 | hashSet.add("u");
20 |
21 | for (let index = 0; index < str.length; index++) {
22 | if (hashSet.has(str.charAt(index))) {
23 | count++;
24 | }
25 | }
26 |
27 | return count;
28 | }
29 |
30 | module.exports = countVowels;
--------------------------------------------------------------------------------
/week-3/03-mongo/solution/middleware/admin.js:
--------------------------------------------------------------------------------
1 | const { Admin } = require("../db");
2 |
3 | // Middleware for handling auth
4 | function adminMiddleware(req, res, next) {
5 | // Implement admin auth logic
6 | // You need to check the headers and validate the admin from the admin DB. Check readme for the exact headers to be expected
7 | const username = req.headers.username; // harkirat@gmail.com
8 | const password = req.headers.password; /// 123456
9 |
10 | Admin.findOne({
11 | username: username,
12 | password: password
13 | })
14 | .then(function(value) {
15 | if (value) {
16 | next();
17 | } else {
18 | res.status(403).json({
19 | msg: "Admin doesnt exist"
20 | })
21 | }
22 | })
23 | }
24 |
25 | module.exports = adminMiddleware;
--------------------------------------------------------------------------------
/week-3/solutions/01-requestcount.js:
--------------------------------------------------------------------------------
1 | const express = require('express');
2 |
3 | const app = express();
4 | let requestCount = 0;
5 |
6 | // You have been given an express server which has a few endpoints.
7 | // Your task is to create a global middleware (app.use) which will
8 | // maintain a count of the number of requests made to the server in the global
9 | // requestCount variable
10 |
11 | app.use(function(req, res, next) {
12 | requestCount = requestCount + 1;
13 | next();
14 | });
15 |
16 | app.get('/user', function(req, res) {
17 | res.status(200).json({ name: 'john' });
18 | });
19 |
20 | app.post('/user', function(req, res) {
21 | res.status(200).json({ msg: 'created dummy user' });
22 | });
23 |
24 | app.get('/requestCount', function(req, res) {
25 | res.status(200).json({ requestCount });
26 | });
27 |
28 | module.exports = app;
--------------------------------------------------------------------------------
/week-3/04-mongo-with-jwt-auth/solution/middleware/admin.js:
--------------------------------------------------------------------------------
1 | const jwt = require("jsonwebtoken");
2 | const {JWT_SECRET} = require("../config");
3 |
4 | // Middleware for handling auth
5 | function adminMiddleware(req, res, next) {
6 | const token = req.headers.authorization; // bearer token
7 | const words = token.split(" "); // ["Bearer", "token"]
8 | const jwtToken = words[1]; // token
9 | try {
10 | const decodedValue = jwt.verify(jwtToken, JWT_SECRET);
11 | if (decodedValue.username) {
12 | next();
13 | } else {
14 | res.status(403).json({
15 | msg: "You are not authenticated"
16 | })
17 | }
18 | } catch(e) {
19 | res.json({
20 | msg: "Incorrect inputs"
21 | })
22 | }
23 |
24 | }
25 |
26 | module.exports = adminMiddleware;
--------------------------------------------------------------------------------
/week-6/1-use-memo/src/components/Assignment1.jsx:
--------------------------------------------------------------------------------
1 | import { useState } from "react";
2 |
3 | // In this assignment, your task is to create a component that performs an expensive calculation (finding the factorial) based on a user input.
4 | // Use useMemo to ensure that the calculation is only recomputed when the input changes, not on every render.
5 |
6 | export function Assignment1() {
7 | const [input, setInput] = useState(0);
8 | // Your solution starts here
9 | const expensiveValue = 0;
10 | // Your solution ends here
11 |
12 | return (
13 |
21 | );
22 | }
--------------------------------------------------------------------------------
/week-3/04-mongo-with-jwt-auth/solution/routes/user.js:
--------------------------------------------------------------------------------
1 | const { Router } = require("express");
2 | const router = Router();
3 | const userMiddleware = require("../middleware/user");
4 |
5 | // User Routes
6 | router.post('/signup', (req, res) => {
7 | // Implement user signup logic
8 | });
9 |
10 | router.post('/signin', (req, res) => {
11 | // Implement admin signup logic
12 | });
13 |
14 | router.get('/courses', (req, res) => {
15 | // Implement listing all courses logic
16 | });
17 |
18 | router.post('/courses/:courseId', userMiddleware, (req, res) => {
19 | // Implement course purchase logic
20 | const username = req.username;
21 | console.log(username);
22 |
23 | });
24 |
25 | router.get('/purchasedCourses', userMiddleware, (req, res) => {
26 | // Implement fetching purchased courses logic
27 | });
28 |
29 | module.exports = router
--------------------------------------------------------------------------------
/week-2/01-async-js/tests/4-promise-chain.test.js:
--------------------------------------------------------------------------------
1 | const calculateTime = require("../hard (promises)/4-promise-chain");
2 |
3 | describe("calculateTime function", () => {
4 | test("calculates time 1", async () => {
5 | const difference = await calculateTime(1, 2, 3);
6 | expect(difference).toBeGreaterThanOrEqual(6000);
7 | expect(difference).toBeLessThan(7000);
8 | }, 7000);
9 |
10 | test("calculates time 2", async () => {
11 | const difference = await calculateTime(10, 1, 1);
12 | expect(difference).toBeGreaterThanOrEqual(12000);
13 | expect(difference).toBeLessThan(13000);
14 | }, 14000);
15 |
16 | test("calculates time for zero seconds", async () => {
17 | const difference = await calculateTime(0, 0, 0);
18 | expect(difference).toBeGreaterThanOrEqual(0);
19 | expect(difference).toBeLessThan(100);
20 | }, 100);
21 | });
22 |
--------------------------------------------------------------------------------
/week-1/offline-class-1/level-2/05-Object.js:
--------------------------------------------------------------------------------
1 | // Object Methods Explanation
2 | function objectMethods(obj) {
3 | console.log("Original Object:", obj);
4 |
5 | let keys = Object.keys(obj);
6 | console.log("After Object.keys():", keys);
7 |
8 | let values = Object.values(obj);
9 | console.log("After Object.values():", values);
10 |
11 | let entries = Object.entries(obj);
12 | console.log("After Object.entries():", entries);
13 |
14 | let hasProp = obj.hasOwnProperty("property");
15 | console.log("After hasOwnProperty():", hasProp);
16 |
17 | let newObj = Object.assign({}, obj, { newProperty: "newValue" });
18 | console.log("After Object.assign():", newObj);
19 |
20 |
21 | }
22 |
23 | // Example Usage for Object Methods
24 | const sampleObject = {
25 | key1: "value1",
26 | key2: "value2",
27 | key3: "value3",
28 | };
29 |
30 | objectMethods(sampleObject);
31 |
--------------------------------------------------------------------------------
/week-3/01-middlewares/03-errorcount.js:
--------------------------------------------------------------------------------
1 | const request = require('supertest');
2 | const assert = require('assert');
3 | const express = require('express');
4 |
5 | const app = express();
6 | let errorCount = 0;
7 |
8 | // You have been given an express server which has a few endpoints.
9 | // Your task is to
10 | // 1. Ensure that if there is ever an exception, the end user sees a status code of 404
11 | // 2. Maintain the errorCount variable whose value should go up every time there is an exception in any endpoint
12 |
13 | app.get('/user', function(req, res) {
14 | throw new Error("User not found");
15 | res.status(200).json({ name: 'john' });
16 | });
17 |
18 | app.post('/user', function(req, res) {
19 | res.status(200).json({ msg: 'created dummy user' });
20 | });
21 |
22 | app.get('/errorCount', function(req, res) {
23 | res.status(200).json({ errorCount });
24 | });
25 |
26 | module.exports = app;
--------------------------------------------------------------------------------
/01-js/medium/times.js:
--------------------------------------------------------------------------------
1 | /*
2 | Write a function that calculates the time (in seconds) it takes for the JS code to calculate sum from 1 to n, given n as the input.
3 | Try running it for
4 | 1. Sum from 1-100
5 | 2. Sum from 1-100000
6 | 3. Sum from 1-1000000000
7 | Hint - use Date class exposed in JS
8 | There is no automated test for this one, this is more for you to understand time goes up as computation goes up
9 | */
10 |
11 | function calculateTime(n) {
12 | let start = performance.now();
13 | let sum = 0;
14 | for (let index = 1; index <= n; index++) {
15 | sum += index;
16 | }
17 | let end = performance.now();
18 | return end - start;
19 | }
20 |
21 | console.log("computation time for 100 is : " + calculateTime(100));
22 | console.log("computation time for 100000 is : " + calculateTime(100000));
23 | console.log("computation time for 1000000000 is : " + calculateTime(1000000000));
--------------------------------------------------------------------------------
/week-3/01-middlewares/tests/01-requestcount.spec.js:
--------------------------------------------------------------------------------
1 | const app = require("../01-requestcount");
2 |
3 | const request = require('supertest');
4 | const assert = require('assert');
5 | describe('GET /user', function() {
6 | it('One request responds with 1', function(done) {
7 | request(app)
8 | .get('/requestCount')
9 | .then(response => {
10 | expect(response.body.requestCount).toBe(1);
11 | done();
12 | })
13 | });
14 |
15 | it('10 more requests log 12', function(done) {
16 | for (let i = 0; i<10; i++) {
17 | request(app)
18 | .get('/user')
19 | .then();
20 | }
21 | request(app)
22 | .get('/requestCount')
23 | .then(response => {
24 | expect(response.body.requestCount).toBe(12);
25 | done();
26 | })
27 | });
28 | });
29 |
30 |
--------------------------------------------------------------------------------
/week-4/README.md:
--------------------------------------------------------------------------------
1 | You have been given the code of a purely frontend TODO app
2 | You have to fill in the following functions -
3 | - addTodoToDom
4 | - removeTodoFromDom
5 | - updateTodoInDom
6 | - updateState
7 |
8 | These 4 functions comprise of what it means to create a library like React.
9 | The goal is the following -
10 | 1. Any time the updateState function is called with a new state, the updateState function calculates the diff between newTodos and oldTodos and call `addTodoToDom`, `removeTodoFromDom` or `updateState` based on the calculated diff.
11 | 2. They id of a todo uniquely identifies it. If the title of a todo with the same id changes in two iterations, updateTodoInDom should be called for it.
12 | 3. The structure of the state variable looks something like this -
13 | ```js
14 | const todos = [{
15 | title: "Go to gym",
16 | description: "Go to gym from 7-8PM",
17 | id: 1
18 | }]
19 | ```
--------------------------------------------------------------------------------
/week-1/offline-class-1/level-2/04-Math.js:
--------------------------------------------------------------------------------
1 | function mathMethods(value) {
2 | console.log("Original Value:", value);
3 |
4 | let rounded = Math.round(value);
5 | console.log("After round():", rounded);
6 |
7 | let ceiling = Math.ceil(value);
8 | console.log("After ceil():", ceiling);
9 |
10 | let flooring = Math.floor(value);
11 | console.log("After floor():", flooring);
12 |
13 | let randomValue = Math.random();
14 | console.log("After random():", randomValue);
15 |
16 | let maxValue = Math.max(5, 10, 15);
17 | console.log("After max():", maxValue);
18 |
19 | let minValue = Math.min(5, 10, 15);
20 | console.log("After min():", minValue);
21 |
22 | let powerOfTwo = Math.pow(value, 2);
23 | console.log("After pow():", powerOfTwo);
24 |
25 | let squareRoot = Math.sqrt(value);
26 | console.log("After sqrt():", squareRoot);
27 | }
28 |
29 | // Example Usage for Math Methods
30 | mathMethods(4.56);
31 | mathMethods(9);
32 | mathMethods(25);
33 |
--------------------------------------------------------------------------------
/week-6/1-use-memo/src/components/Assignment3.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState, useMemo } from 'react';
2 | // You have been given a list of items you shopped from the grocery store
3 | // You need to calculate the total amount of money you spent
4 |
5 | export const Assignment3 = () => {
6 | const [items, setItems] = useState([
7 | { name: 'Chocolates', value: 10 },
8 | { name: 'Chips', value: 20 },
9 | { name: 'Onion', value: 30 },
10 | { name: 'Tomato', value: 30 },
11 | // Add more items as needed
12 | ]);
13 |
14 | // Your code starts here
15 | const totalValue = 0;
16 | // Your code ends here
17 | return (
18 |
19 |
20 | {items.map((item, index) => (
21 |
{item.name} - Price: ${item.value}
22 | ))}
23 |
24 |
Total Value: {totalValue}
25 |
26 | );
27 | };
28 |
--------------------------------------------------------------------------------
/week-3/01-middlewares/02-ratelimitter.js:
--------------------------------------------------------------------------------
1 | const request = require('supertest');
2 | const assert = require('assert');
3 | const express = require('express');
4 | const app = express();
5 | // You have been given an express server which has a few endpoints.
6 | // Your task is to create a global middleware (app.use) which will
7 | // rate limit the requests from a user to only 5 request per second
8 | // If a user sends more than 5 requests in a single second, the server
9 | // should block them with a 404.
10 | // User will be sending in their user id in the header as 'user-id'
11 | // You have been given a numberOfRequestsForUser object to start off with which
12 | // clears every one second
13 |
14 | let numberOfRequestsForUser = {};
15 | setInterval(() => {
16 | numberOfRequestsForUser = {};
17 | }, 1000)
18 |
19 | app.get('/user', function(req, res) {
20 | res.status(200).json({ name: 'john' });
21 | });
22 |
23 | app.post('/user', function(req, res) {
24 | res.status(200).json({ msg: 'created dummy user' });
25 | });
26 |
27 | module.exports = app;
--------------------------------------------------------------------------------
/week-6/2-use-callback/src/components/Assignment1.jsx:
--------------------------------------------------------------------------------
1 | import { useState } from "react";
2 |
3 | // Create a counter component with increment and decrement functions. Pass these functions to a child component which has buttons to perform the increment and decrement actions. Use useCallback to ensure that these functions are not recreated on every render.
4 |
5 | export function Assignment1() {
6 | const [count, setCount] = useState(0);
7 |
8 | // Your code starts here
9 | function handleIncrement() {
10 |
11 | }
12 |
13 | function handleDecrement() {
14 |
15 | }
16 | // Your code ends here
17 |
18 | return (
19 |
31 | );
32 |
--------------------------------------------------------------------------------
/week-6/solutions/1/components/Assignment1.jsx:
--------------------------------------------------------------------------------
1 | import { useMemo, useState } from "react";
2 |
3 | // In this assignment, your task is to create a component that performs an expensive calculation (finding the factorial) based on a user input.
4 | // Use useMemo to ensure that the calculation is only recomputed when the input changes, not on every render.
5 |
6 | export function Assignment1() {
7 | const [input, setInput] = useState(0);
8 |
9 | const expensiveValue = useMemo(() => {
10 | // Your solution starts here
11 | let value = 1;
12 | for (let i = 1; i <= input; i++) {
13 | value = value * i;
14 | }
15 | return value;
16 | }, [input]);
17 |
18 | // Your solution ends here
19 |
20 | return (
21 |
35 | ));
36 |
--------------------------------------------------------------------------------
/week-6/2-use-callback/src/components/Assignment2.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState, useCallback } from 'react';
2 |
3 | // Create a component with a text input field and a button. The goal is to display an alert with the text entered when the button is clicked. Use useCallback to memoize the event handler function that triggers the alert, ensuring it's not recreated on every render.
4 | // Currently we only have inputText as a state variable and hence you might not see the benefits of
5 | // useCallback. We're also not passing it down to another component as a prop which is another reason for you to not see it's benefits immedietely.
6 |
7 | export function Assignment2() {
8 | const [inputText, setInputText] = useState('');
9 |
10 | // Your code starts here
11 | function showAlert() {
12 |
13 | }
14 | // Your code ends here
15 |
16 | return (
17 |
26 | );
27 | };
28 |
29 | function Alert({showAlert}) {
30 | return
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/week-6/solutions/2/components/Assignment2.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState, useCallback } from 'react';
2 |
3 | // Create a component with a text input field and a button. The goal is to display an alert with the text entered when the button is clicked. Use useCallback to memoize the event handler function that triggers the alert, ensuring it's not recreated on every render.
4 | // Currently we only have inputText as a state variable and hence you might not see the benefits of
5 | // useCallback. We're also not passing it down to another component as a prop which is another reason for you to not see it's benefits immedietely.
6 |
7 | export function Assignment2() {
8 | const [inputText, setInputText] = useState('');
9 |
10 | // Your code starts here
11 | const showAlert = useCallback(() => {
12 | alert(inputText);
13 | }, [inputText])
14 | // Your code ends here
15 |
16 | return (
17 |
26 | );
27 | };
28 |
29 | function Alert({showAlert}) {
30 | return
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/week-3/01-middlewares/tests/02-ratelimitter.spec.js:
--------------------------------------------------------------------------------
1 | const app = require("../02-ratelimitter");
2 |
3 | const request = require('supertest');
4 | const assert = require('assert');
5 | describe('GET /user', function () {
6 | const userId = 'testId'
7 | it('One request responds back correctly', function(done) {
8 | request(app)
9 | .get('/user')
10 | .set('user-id', userId)
11 | .then((response) => {
12 | expect(response.status).toBe(200);
13 | done();
14 | });
15 | });
16 |
17 | it('5 or more requests return back a 404', function(done) {
18 | for (let i = 0; i<5; i++) {
19 | request(app).get('/user').set('user-id', userId).then();
20 | }
21 | request(app)
22 | .get('/user')
23 | .set('user-id', userId)
24 | .then((response) => {
25 | expect(response.status).toBe(404);
26 | done();
27 | });
28 | });
29 |
30 | it('5 or more requests and waiting returns a 200', function(done) {
31 | for (let i = 0; i<5; i++) {
32 | request(app).get('/user').set('user-id', userId).then();
33 | }
34 | setTimeout(function() {
35 | request(app)
36 | .get('/user')
37 | .set('user-id', userId)
38 | .then((response) => {
39 | expect(response.status).toBe(200);
40 | done();
41 | });
42 | }, 2000);
43 | });
44 | });
45 |
46 |
--------------------------------------------------------------------------------
/week-2/02-nodejs/README.md:
--------------------------------------------------------------------------------
1 | ## Node.js Assignments
2 | In this series of assignments, you are going to create native HTTP servers in Node.js which will handle different kinds of application logics.
3 |
4 | You are provided empty JavaScript files (or having function signatures) in this directory. You have to follow the instructions given in each file and then run automated tests (also mentioned in each file) to check if you have successfully completed the assignment or you still have few more things to learn in it 😜
5 |
6 | ### Assignments
7 | Recommended order of attempting the assignments.
8 | 1. Todo List App
9 | 2. File Server
10 |
11 | #### Important Notes
12 | 1. If you are unable to understand the request/response of any assignment file or whatever the way it is being tested, you can take a look at its respective test file present in `tests/` directory.
13 | 2. Don't try to make any changes to the test files present in the `tests/` directory.
14 | 3. Don't make any changes to the code already present in files including function/method/class signatures and module exports.
15 | 4. To run individual tests -
16 | - npm run test-fileServer
17 | - npm run test-todoServer
18 |
19 | #### Development Setup
20 | 1. Install the dependencies used by running `npm install` command in your terminal.
21 | 2. We used `18.x.y` Node.js version, if anything doesn't work then please consider upgrading your node installation.
22 |
--------------------------------------------------------------------------------
/week-3/solutions/02-ratelimitter.js:
--------------------------------------------------------------------------------
1 |
2 | const express = require('express');
3 | const app = express();
4 | // You have been given an express server which has a few endpoints.
5 | // Your task is to create a global middleware (app.use) which will
6 | // rate limit the requests from a user to only 5 request per second
7 | // If a user sends more than 5 requests in a single second, the server
8 | // should block them with a 404.
9 | // User will be sending in their user id in the header as 'user-id'
10 | // You have been given a numberOfRequestsForUser object to start off with which
11 | // clears every one second
12 |
13 | let numberOfRequestsForUser = {};
14 | setInterval(() => {
15 | numberOfRequestsForUser = {};
16 | }, 1000)
17 | //
18 | app.use(function(req, res, next) {
19 | const userId = req.headers["user-id"];
20 |
21 | if (numberOfRequestsForUser[userId]) {
22 | numberOfRequestsForUser[userId] = numberOfRequestsForUser[userId] + 1;
23 | if (numberOfRequestsForUser[userId] > 5) {
24 | res.status(404).send("no entry");
25 | } else {
26 | next();
27 | }
28 | } else {
29 | numberOfRequestsForUser[userId] = 1;
30 | next();
31 | }
32 | })
33 |
34 |
35 | app.get('/user', function(req, res) {
36 | res.status(200).json({ name: 'john' });
37 | });
38 |
39 | app.post('/user', function(req, res) {
40 | res.status(200).json({ msg: 'created dummy user' });
41 | });
42 |
43 | module.exports = app;
--------------------------------------------------------------------------------
/week-6/1-use-memo/src/components/Assignment2.jsx:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from "react";
2 |
3 | // In this assignment, you will create a component that renders a large list of sentences and includes an input field for filtering these items.
4 | // The goal is to use useMemo to optimize the filtering process, ensuring the list is only re-calculated when necessary (e.g., when the filter criteria changes).
5 | // You will learn something new here, specifically how you have to pass more than one value in the dependency array
6 |
7 | const words = ["hi", "my", "name", "is", "for", "to", "random", "word" ];
8 | const TOTAL_LINES = 1000;
9 | const ALL_WORDS = [];
10 | for (let i = 0; i < TOTAL_LINES; i++) {
11 | let sentence = "";
12 | for (let j = 0; j < words.length; j++) {
13 | sentence += (words[Math.floor(words.length * Math.random())])
14 | sentence += " "
15 | }
16 | ALL_WORDS.push(sentence);
17 | }
18 |
19 | export function Assignment2() {
20 | const [sentences, setSentences] = useState(ALL_WORDS);
21 | const [filter, setFilter] = useState("");
22 |
23 | const filteredSentences = sentences.filter(x => x.includes(filter))
24 |
25 | return