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

Assignment by Komal Kafaltiya #18

Open
wants to merge 1 commit 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
95 changes: 95 additions & 0 deletions challenge 1/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Approximate Search - Challenge 1</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 2rem;
}
h1{
text-align: center;
font-size: 60px;
color:rgb(110, 74, 74);
}
input {
padding: 0.9rem;
width: 98%;
margin-bottom: 1rem;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 25px;
}
.suggestions {
list-style: none;
padding: 0;
}
.suggestions li {
padding: 0.5rem;
border-bottom: 1px solid #ddd;
}
</style>
</head>
<body>
<h1>Approximate Search - Challenge 1</h1>
<input type="text" id="searchInput" placeholder="Type a word..." />
<ul id="suggestions" class="suggestions"></ul>

<script>
const words = [
"absolutely",
"active",
"activity",
"activist",
"accurate",
"abstract",
"accessible",
"accessible",
];

// Levenshtein Distance function
const levenshtein = (a, b) => {
const dp = Array(b.length + 1)
.fill()
.map((_, i) => i);
for (let i = 1; i <= a.length; i++) {
let prev = i;
for (let j = 1; j <= b.length; j++) {
const temp = dp[j];
dp[j] =
a[i - 1] === b[j - 1]
? prev
: Math.min(dp[j - 1], dp[j], prev) + 1;
prev = temp;
}
}
return dp[b.length];
};

// Event listener for input
document
.getElementById("searchInput")
.addEventListener("input", function () {
const input = this.value.trim();
const suggestionsList = document.getElementById("suggestions");
suggestionsList.innerHTML = ""; // Clear current suggestions

if (input) {
const suggestions = words
.map((word) => ({ word, dist: levenshtein(input, word) }))
.sort((a, b) => a.dist - b.dist)
.slice(0, 3)
.map((item) => item.word);

suggestions.forEach((suggestion) => {
const li = document.createElement("li");
li.textContent = suggestion;
suggestionsList.appendChild(li);
});
}
});
</script>
</body>
</html>
1 change: 1 addition & 0 deletions challenge 1/wordList.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
absolutely active activity activist accurate abstract accessible achievable action adapt adore agile align alien amplify ambition anecdote komal
81 changes: 81 additions & 0 deletions challenge 2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Arithmetic Expression Solver - Challenge 2</title>
</head>
<body>
<h1>Arithmetic Expression Solver - Challenge 2</h1>
<input type="file" id="fileInput" accept=".txt" />
<button onclick="processFile()">Solve Expressions</button>
<a id="downloadLink" style="display: none">Download Result</a>

<script>
function isValidExpression(expr) {
return /^[0-9+\-*/^().\[\]{} ]+$/.test(expr); //regex expression
}

function cleanExpression(expr) {
expr = expr.replace(/–|—/g, "-");
expr = expr.replace(/(\d)\(/g, "$1*(");
expr = expr.replace(/\)(\d)/g, ")*$1");
expr = expr.replace(/\)\(/g, ")*(");

return expr;
}

function evaluateExpression(expr) {
try {
expr = expr.replace(/\^/g, "**");
return Function(`"use strict"; return (${expr});`)();
} catch (e) {
return "Invalid Expression";
}
}

function processFile() {
const fileInput = document.getElementById("fileInput");
if (fileInput.files.length === 0) {
alert("Please select a file.");
return;
}

const file = fileInput.files[0];
const reader = new FileReader();

reader.onload = function () {
const lines = reader.result.split("\n");
const outputLines = [];

lines.forEach((line) => {
line = line.trim();
if (line.endsWith("=")) {
const expression = cleanExpression(line.slice(0, -1).trim());
if (isValidExpression(expression)) {
const result = evaluateExpression(expression);
outputLines.push(`${line} ${result}`);
} else {
outputLines.push(`${line} Invalid Expression`);
}
} else {
outputLines.push(`${line} Invalid Expression`);
}
});

// output file for download
const outputContent = outputLines.join("\n");
const blob = new Blob([outputContent], { type: "text/plain" });
const url = URL.createObjectURL(blob);
const downloadLink = document.getElementById("downloadLink");
downloadLink.href = url;
downloadLink.download = "output.txt";
downloadLink.style.display = "block";
downloadLink.textContent = "Download Result File";
};

reader.readAsText(file);
}
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions challenge 2/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
10 – 2 =
100 * ( 2 + 12 ) =
(10 + 5^2) ( (5*-2) + 9 - 3^3) / 2 =
5 changes: 5 additions & 0 deletions challenge 3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Start Guide

Initialize npm and Install Dependencies:
Run npm init -y to initialize a new npm project with default settings.
Install nodemailer by running npm install nodemailer.
Binary file added challenge 3/komal_kafaltiya.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions challenge 3/sendEmail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const nodemailer = require('nodemailer');
const fs = require('fs');
const path = require('path');

// Sender and receiver information
const senderEmail = '[email protected]';
const senderPassword = 'password'; // due to security reaosn i am not putting my email address here
const receiverEmail = '[email protected]';

// Email content
const subject = 'Challenge 3 Completed';
const body = `
Name: Komal Kafaltiya
Semester: 4
Branch: CS-IT
Roll Number: 21256342
`;

const imagePath = './komal_kafaltiya.png';
const validImageTypes = ['.png', '.jpg', '.jpeg'];
const imageExtension = path.extname(imagePath).toLowerCase();

if (!fs.existsSync(imagePath)) {
console.error('Image file not found at the specified path.');
process.exit(1);
}

if (!validImageTypes.includes(imageExtension)) {
console.error('Invalid image type. Only PNG, JPG, JPEG are allowed.');
process.exit(1);
}

const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: senderEmail,
pass: senderPassword,
},
});

const mailOptions = {
from: senderEmail,
to: receiverEmail,
subject: subject,
text: body,
attachments: [
{
filename: path.basename(imagePath),
path: imagePath,
},
],
};

// Send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.error('An error occurred while sending the email:', error);
}
console.log('Email sent successfully! Message ID:', info.messageId);
});



52 changes: 52 additions & 0 deletions challenge 4/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Palindrome Checker - Challenge 4</title>
<style>
h1 {
text-align: center;
color: skyblue;
font-size: 70px;
}
button{
display: block;
margin:0 auto;
padding: 10px 40px;
font-size: 25px;
color:grey;
background-color:aliceblue;
border: 1px solid black;
}
#result{
font-size: 25px;
text-align: center;
}
</style>
</head>

<body>
<h1> Palindrome Checker - Challenge 4 </h1>
<button onclick="checkPalindrome()"> Check </button>
<p id="result"> </p>

<script>
function checkPalindrome() {
var word = prompt("Enter any String:");
var letters = word.split("");
var reversedLetters = letters.reverse();
var joinWord = reversedLetters.join("");

if (joinWord.toLowerCase() == word.toLowerCase()) {
document.getElementById("result").innerText = "The given word is a palindrome";
}
else {
document.getElementById("result").innerText = "The given word is not a palindrome";
}
}
</script>
</body>

</html>