-
Notifications
You must be signed in to change notification settings - Fork 32
Durga arrays js #537
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
base: main
Are you sure you want to change the base?
Durga arrays js #537
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
|
|
||
| * { | ||
| margin: 0; | ||
| padding: 0; | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| body { | ||
| font-family: Arial, sans-serif; | ||
| line-height: 1.6; | ||
| } | ||
|
|
||
| header { | ||
| background: #0d0a99; | ||
| color: #fff; | ||
| padding: 20px; | ||
| text-align: center; | ||
| } | ||
|
|
||
| nav ul { | ||
| list-style: none; | ||
| display: flex; | ||
| justify-content: center; | ||
| gap: 20px; | ||
| margin-top: 10px; | ||
| } | ||
|
|
||
| nav a { | ||
| color: #fff; | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| main { | ||
| display: flex; | ||
| padding: 20px; | ||
| gap: 20px; | ||
| } | ||
|
|
||
| article { | ||
| flex: 3; | ||
| background: #2c13a8; | ||
| color: #fff; | ||
| padding: 20px; | ||
| border-radius: 8px; | ||
| } | ||
|
|
||
| aside { | ||
| flex: 1; | ||
| background: #4d119b; | ||
| color: #fff; | ||
| padding: 20px; | ||
| border-radius: 8px; | ||
| } | ||
|
|
||
| footer { | ||
| background: #3f12ba; | ||
| color: #fff; | ||
| text-align: center; | ||
| padding: 15px; | ||
| margin-top: 20px; | ||
| bottom: auto; | ||
| } | ||
|
|
||
| @media (max-width: 768px) { | ||
| main { | ||
| flex-direction: column; | ||
| flex:1; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>CSS Animation & Media Queries</title> | ||
| <style> | ||
| body { | ||
| font-family: Arial, sans-serif; | ||
| margin: 0; | ||
| padding: 0; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| height: 100vh; | ||
| background: #f0f0f0; | ||
| } | ||
| .box { | ||
| width: 150px; | ||
| height: 150px; | ||
| background: #3498db; | ||
| border-radius: 10px; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| color: white; | ||
| font-weight: bold; | ||
| animation: bounce 2s infinite; | ||
| } | ||
| @keyframes bounce { | ||
| 0%, 100% { | ||
| transform: translateY(0); | ||
| } | ||
| 50% { | ||
| transform: translateY(-50px); | ||
| } | ||
| } | ||
| @media (max-width: 768px) { | ||
| .box { | ||
| width: 120px; | ||
| height: 120px; | ||
| font-size: 14px; | ||
| background: #e67e22; | ||
| } | ||
| } | ||
|
|
||
| @media (max-width: 480px) { | ||
| .box { | ||
| width: 90px; | ||
| height: 90px; | ||
| font-size: 12px; | ||
| background: #2ecc71; | ||
| } | ||
| } | ||
| </style> | ||
|
Comment on lines
+7
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR description includes a checklist for best practices, which states to "Avoid inline styles unless absolutely necessary" and "Use modular CSS files". Placing a large block of CSS within a |
||
| </head> | ||
| <body> | ||
| <div class="box">Hello Guys..!</div> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||||||||||||||||||||||||||||||||||||||
| <!DOCTYPE html> | ||||||||||||||||||||||||||||||||||||||||||
| <html lang="en"> | ||||||||||||||||||||||||||||||||||||||||||
| <head> | ||||||||||||||||||||||||||||||||||||||||||
| <meta charset="UTF-8"> | ||||||||||||||||||||||||||||||||||||||||||
| <title>My Personal Homepage</title> | ||||||||||||||||||||||||||||||||||||||||||
| </head> | ||||||||||||||||||||||||||||||||||||||||||
| <body> | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| <header> | ||||||||||||||||||||||||||||||||||||||||||
| <h1>Welcome to My Homepage</h1> | ||||||||||||||||||||||||||||||||||||||||||
| <p>A short introduction about myself</p> | ||||||||||||||||||||||||||||||||||||||||||
| </header> | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| <main> | ||||||||||||||||||||||||||||||||||||||||||
| <section id="about"> | ||||||||||||||||||||||||||||||||||||||||||
| <h2>About Me</h2> | ||||||||||||||||||||||||||||||||||||||||||
| <p>Hello! My name is Sai Durga. I am passionate about web development and always eager to learn new technologies.</p> | ||||||||||||||||||||||||||||||||||||||||||
| </section> | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| <section id="education"> | ||||||||||||||||||||||||||||||||||||||||||
| <h2>Education</h2> | ||||||||||||||||||||||||||||||||||||||||||
| <p>I am a recent Graduate of <strong>Bachelor’s Degree</strong> in Information Technology.</p> | ||||||||||||||||||||||||||||||||||||||||||
| </section> | ||||||||||||||||||||||||||||||||||||||||||
| <section id="skills"> | ||||||||||||||||||||||||||||||||||||||||||
| <h2>Skills</h2> | ||||||||||||||||||||||||||||||||||||||||||
| <ul> | ||||||||||||||||||||||||||||||||||||||||||
| <li>HTML5 & CSS3</li> | ||||||||||||||||||||||||||||||||||||||||||
| <li>JavaScript</li> | ||||||||||||||||||||||||||||||||||||||||||
| <li>Java</li> | ||||||||||||||||||||||||||||||||||||||||||
| <li>SQL</li> | ||||||||||||||||||||||||||||||||||||||||||
| </ul> | ||||||||||||||||||||||||||||||||||||||||||
| </section> | ||||||||||||||||||||||||||||||||||||||||||
| <section id="contact"> | ||||||||||||||||||||||||||||||||||||||||||
| <h2>Contact Me</h2> | ||||||||||||||||||||||||||||||||||||||||||
| <form> | ||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| <label for="name">Full Name:</label><br> | ||||||||||||||||||||||||||||||||||||||||||
| <input type="text" id="name" name="name" required><br><br> | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| <label for="email">Email Address:</label><br> | ||||||||||||||||||||||||||||||||||||||||||
| <input type="email" id="email" name="email" required><br><br> | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| <label for="dob">Date of Birth:</label><br> | ||||||||||||||||||||||||||||||||||||||||||
| <input type="date" id="dob" name="dob"><br><br> | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| <label for="message">Message:</label><br> | ||||||||||||||||||||||||||||||||||||||||||
| <textarea id="message" name="message" rows="4"></textarea><br><br> | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+37
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| <input type="submit" value="Send"> | ||||||||||||||||||||||||||||||||||||||||||
| </form> | ||||||||||||||||||||||||||||||||||||||||||
| </section> | ||||||||||||||||||||||||||||||||||||||||||
| </main> | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| <footer> | ||||||||||||||||||||||||||||||||||||||||||
| <p>© 2025 Sai Durga. All rights reserved.</p> | ||||||||||||||||||||||||||||||||||||||||||
| </footer> | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| </body> | ||||||||||||||||||||||||||||||||||||||||||
| </html> | ||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||
| <!DOCTYPE html> | ||||||
| <html lang="en"> | ||||||
| <head> | ||||||
| <meta charset="UTF-8"> | ||||||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||||
| <title>Custom Array Flatten</title> | ||||||
| <link rel="stylesheet" href="style.css"> | ||||||
| </head> | ||||||
| <body> | ||||||
| <h2>Custom Array Flatten Function</h2> | ||||||
|
|
||||||
| <div class="container"> | ||||||
| <label>Enter Nested Array:</label><br> | ||||||
| <input type="text" id="inputArray" placeholder='Ex: [1,2,[3,5],[5,[6,7]]]' size="40"> | ||||||
| <br><br> | ||||||
| <button onclick="flattenArray()">Flatten Array</button> | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||
|
|
||||||
| <h3>Result:</h3> | ||||||
| <p id="result"></p> | ||||||
| </div> | ||||||
|
|
||||||
| <script src="script.js"></script> | ||||||
| </body> | ||||||
| </html> | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||
| // Function to recursively flatten an array | ||||||
| function customFlatten(arr) { | ||||||
| let result = []; | ||||||
| for (let element of arr) { | ||||||
| if (Array.isArray(element)) { | ||||||
| result = result.concat(customFlatten(element)); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||
| } else { | ||||||
| result.push(element); | ||||||
| } | ||||||
| } | ||||||
| return result; | ||||||
| } | ||||||
|
|
||||||
| function flattenArray() { | ||||||
| let input = document.getElementById("inputArray").value; | ||||||
|
|
||||||
| try { | ||||||
| let arr = JSON.parse(input); | ||||||
| let flattened = customFlatten(arr); | ||||||
| document.getElementById("result").innerHTML = `[ ${flattened.join(", ")} ]`; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a best practice to use
Suggested change
|
||||||
| } catch (error) { | ||||||
| document.getElementById("result").innerHTML = "❌ Invalid input! Please enter a valid array format."; | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| body { | ||
| font-family: Arial, sans-serif; | ||
| background-color: #f7f9fc; | ||
| text-align: center; | ||
| margin-top: 50px; | ||
| } | ||
|
|
||
| .container { | ||
| display: inline-block; | ||
| background-color: #fff; | ||
| padding: 20px 30px; | ||
| border-radius: 12px; | ||
| box-shadow: 0 4px 8px rgba(0,0,0,0.2); | ||
| } | ||
|
|
||
| input { | ||
| padding: 8px; | ||
| font-size: 16px; | ||
| width: 70%; | ||
| border-radius: 6px; | ||
| border: 1px solid #ccc; | ||
| } | ||
|
|
||
| button { | ||
| padding: 10px 20px; | ||
| background-color: #007bff; | ||
| color: white; | ||
| border: none; | ||
| border-radius: 6px; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| button:hover { | ||
| background-color: #0056b3; | ||
| } | ||
|
|
||
| #result { | ||
| margin-top: 15px; | ||
| font-size: 18px; | ||
| font-weight: bold; | ||
| color: #333; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,23 @@ | ||||||
| <!DOCTYPE html> | ||||||
| <html lang="en"> | ||||||
| <head> | ||||||
| <meta charset="UTF-8"> | ||||||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||||
| <title>Array Loop Performance Comparison</title> | ||||||
| <link rel="stylesheet" href="style.css"> | ||||||
| </head> | ||||||
| <body> | ||||||
| <h2>16. Performance Optimization – Loop Comparison</h2> | ||||||
|
|
||||||
| <div class="container"> | ||||||
| <label>Enter Array Size:</label> | ||||||
| <input type="number" id="arraySize" placeholder="e.g. 1000000"> | ||||||
| <button onclick="comparePerformance()">Compare</button> | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||
|
|
||||||
| <h3>Results:</h3> | ||||||
| <pre id="output"></pre> | ||||||
| </div> | ||||||
|
|
||||||
| <script src="script.js"></script> | ||||||
| </body> | ||||||
| </html> | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| function comparePerformance() { | ||
| const size = parseInt(document.getElementById("arraySize").value); | ||
| const output = document.getElementById("output"); | ||
|
|
||
| if (!size || size <= 0) { | ||
| alert("Please enter a valid array size!"); | ||
| return; | ||
| } | ||
|
|
||
| const arr = Array.from({ length: size }, (_, i) => i); | ||
|
|
||
| let result = ""; | ||
| let start = performance.now(); | ||
| let sum = 0; | ||
| for (let i = 0; i < arr.length; i++) { | ||
| sum += arr[i]; | ||
| } | ||
| let forTime = performance.now() - start; | ||
| result += `for loop: ${forTime.toFixed(3)} ms\n`; | ||
| start = performance.now(); | ||
| sum = 0; | ||
| for (const num of arr) { | ||
| sum += num; | ||
| } | ||
| let forOfTime = performance.now() - start; | ||
| result += `for...of loop: ${forOfTime.toFixed(3)} ms\n`; | ||
|
|
||
| start = performance.now(); | ||
| sum = 0; | ||
| arr.forEach(num => sum += num); | ||
| let forEachTime = performance.now() - start; | ||
| result += `forEach loop: ${forEachTime.toFixed(3)} ms\n`; | ||
| result += `\nFastest: ${Math.min(forTime, forOfTime, forEachTime) === forTime ? "for loop" : Math.min(forOfTime, forEachTime) === forOfTime ? "for...of loop" : "forEach loop"}`; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This long, nested ternary operator is difficult to read and understand. For better maintainability, it should be refactored into a more readable structure. This will also make the code easier to extend if you decide to compare more looping methods in the future. Here's an example of a more readable approach: const times = {
'for loop': forTime,
'for...of loop': forOfTime,
'forEach loop': forEachTime
};
let fastestLoop = '';
let minTime = Infinity;
for (const loop in times) {
if (times[loop] < minTime) {
minTime = times[loop];
fastestLoop = loop;
}
}
result += `\nFastest: ${fastestLoop}`; |
||
|
|
||
| output.textContent = result; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| body { | ||
| font-family: Arial, sans-serif; | ||
| background-color: #f3f6fa; | ||
| padding: 20px; | ||
| } | ||
|
|
||
| .container { | ||
| background-color: white; | ||
| padding: 20px; | ||
| border-radius: 10px; | ||
| width: 420px; | ||
| box-shadow: 0 2px 5px rgba(0,0,0,0.1); | ||
| } | ||
|
|
||
| input { | ||
| width: 100%; | ||
| margin: 8px 0; | ||
| padding: 8px; | ||
| border: 1px solid #ccc; | ||
| border-radius: 5px; | ||
| } | ||
|
|
||
| button { | ||
| background-color: #007bff; | ||
| color: white; | ||
| border: none; | ||
| padding: 8px 14px; | ||
| border-radius: 6px; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| button:hover { | ||
| background-color: #0056b3; | ||
| } | ||
|
|
||
| pre { | ||
| background-color: #f2f2f2; | ||
| padding: 12px; | ||
| border-radius: 6px; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
flex: 1property here will have no effect because its parent, the<body>element, is not a flex container. This line appears to be unnecessary and can be removed without changing the layout.