Skip to content
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
23 changes: 20 additions & 3 deletions 01-js/easy/anagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,28 @@
- A word, phrase, or name formed by rearranging the letters of another, such as spar, formed from rasp.

Once you've implemented the logic, test your code by running
- `npm run test-anagram`
- `npm run test-angram`
*/

function isAnagram(str1, str2) {
function ConvertToSmall(str){
let d = "";
for(let i = 0;i<str.length;i++)
{
if(str.charCodeAt(i)>=65 && str.charCodeAt(i)<=90)
d+= String.fromCharCode(str.charCodeAt(i)+32);
else
d+= str[i];
}
return d;
}

function isAnagram(str1, str2) {
str1 = ConvertToSmall(str1);
str2 = ConvertToSmall(str2);
if(str1.split("").sort().join("") === str2.split("").sort().join(""))
return true;
else
return false;
}

module.exports = isAnagram;
module.exports = isAnagram;
16 changes: 15 additions & 1 deletion 01-js/easy/expenditure-analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,21 @@
*/

function calculateTotalSpentByCategory(transactions) {
return [];
let arr = [];
let k = 0;
for(let i = 0;i<transactions.length;i++){
if(transactions[i].category != ""){
arr[k] = {category: transactions[i].category, totalSpent: transactions[i].price};
for(let j = i+1;j<transactions.length;j++){
if(transactions[i].category == transactions[j].category){
arr[k].totalSpent+=transactions[j].price;
transactions[j].category = "";
}
}
k++;
}
}
return arr;
}

module.exports = calculateTotalSpentByCategory;
13 changes: 13 additions & 0 deletions 01-js/medium/palindrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,21 @@
- `npm run test-palindrome`
*/

function removePunctuation(str1) {
let s = "";
for (let i = 0; i < str1.length; i++) {
if ((str1.charCodeAt(i) >= 97 && str1.charCodeAt(i) <= 122))
s += str1[i];
}
return s;
}
function isPalindrome(str) {
str = str.toLowerCase();
str = removePunctuation(str);
if(str == str.split("").reverse().join(""))
return true;
else
return false;
}

module.exports = isPalindrome;
12 changes: 9 additions & 3 deletions 01-js/medium/times.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Try running it for
Hint - use Date class exposed in JS
*/

function calculateTime(n) {
return 0.01;
}
function calculateTime() {
let sum = 0;
let startTime = new Date().getTime();
for(let i = 1;i<=10000000;i++)
sum+=i;
let endTime = new Date().getTime();
console.log((endTime-startTime)/1000);
}
calculateTime();
13 changes: 13 additions & 0 deletions 01-js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions 02-async-js/easy/easy-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let i = 0;
function counter(){
console.log(++i);
console.clear();
}
setInterval(counter,1000);
7 changes: 7 additions & 0 deletions 02-async-js/easy/easy-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let i = 0;
counter_2();
function counter_2(){
console.log(++i);
setTimeout(counter_2,1000);
}

9 changes: 9 additions & 0 deletions 02-async-js/easy/easy-3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fs = require('fs');

fs.readFile('02-async-js/easy/easy-1.js','utf8',function(err, data){
if(err) {
console.error(err);
return;
}
console.log(data);
});
8 changes: 8 additions & 0 deletions 02-async-js/medium/createClock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function printTime(){
let hour = new Date().getHours();
let min = new Date().getMinutes();
let sec = new Date().getSeconds();
console.log(hour+":"+min+":"+sec);
}

setInterval(printTime,1000);
30 changes: 30 additions & 0 deletions 02-async-js/medium/medium-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const fs = require('fs');
let text;
let str = "";
let check = true;
function printData(err,data){
if(err){
console.log(err);
}
text = data;
for(let i = 0;i<text.length;i++){
if(text[i] === ' ' && check === true){
str+=' ';
check = false;
}
else
if(text[i] !== ' '){
str+=text[i];
check = true;
}
}
fs.writeFile('02-async-js/medium/removeSpace.txt',str,(err) => {
if (err) {
console.error('Error writing to file:', err);
} else {
console.log('Data has been written to the file successfully!');
}
});
}
fs.readFile('02-async-js/medium/removeSpace.txt','utf-8',printData);

1 change: 1 addition & 0 deletions 02-async-js/medium/removeSpace.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Binay Pratap Singh