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
12 changes: 12 additions & 0 deletions 01-js/easy/anagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,21 @@
Once you've implemented the logic, test your code by running
- `npm run test-anagram`
*/
function sort(str){
let arr = str.split("");
arr.sort();
let ans = arr.join("");

return ans;
}
function isAnagram(str1, str2) {

if(sort(str1.toLowerCase())==sort(str2.toLowerCase())){
return true;
}
else {
return false;
}
}

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

function calculateTotalSpentByCategory(transactions) {
return [];

let arr = {};
let size = Object.keys(transactions).length;
for(let i=0;i<size;i++){
let t = transactions[i];
if(arr[t.category]){
arr[t.category]=arr[t.category]+t.price;
}
else {
arr[t.category]=t.price;
}
}
let keys=Object.keys(arr);
let ans = [];
for(let i=0;i<keys.length;i++){
let category=keys[i];

let obj = {
category:category,
totalSpent:arr[category]
}

ans.push(obj);
console.log(ans);
}
return ans;
}

module.exports = calculateTotalSpentByCategory;

// let transactions =[
// {itemName:"Samosa",
// category:"Food",
// price:15,
// timestamp:38443 },
// {itemName:"Mirinda",
// category:"Drink",
// price:35,
// timestamp:3483 },
// {itemName:"Fruti",
// category:"Drink",
// price:20,
// timestamp:8349}
// ]
// let ans = calculateTotalSpentByCategory(transactions)
// console.log(ans);
// console.log(calculateTotalSpentByCategory(transactions));


13 changes: 13 additions & 0 deletions 01-js/medium/palindrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@
*/

function isPalindrome(str) {
let s = str ;
s= s.toLowerCase();
str = str.toLowerCase();
let a = str.length-1;
for(let i = 0;i<a/2;i++){
let temp = str[i];
str[i]=str[a-i];
str[a-i]=temp;
}
if(s!=str){
return false;
}
return true;
}

module.exports = isPalindrome;
isPalindrome("hello help me")
7 changes: 5 additions & 2 deletions 01-js/medium/times.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ Hint - use Date class exposed in JS
*/

function calculateTime(n) {
return 0.01;
}

let ans = new Date();
console.log(ans);
}
calculateTime(1);