Skip to content

Commit 7e0d07f

Browse files
author
Drago
committed
solution
1 parent c428b96 commit 7e0d07f

File tree

7 files changed

+99
-8
lines changed

7 files changed

+99
-8
lines changed

01-js/easy/anagram.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,30 @@
44
- A word, phrase, or name formed by rearranging the letters of another, such as spar, formed from rasp.
55
*/
66

7-
function isAnagram(str1, str2) {
7+
function isAnagram(str1, str2){
8+
let sizeStr1 = str1.length;
9+
let sizeStr2 = str2.length;
810

11+
if(sizeStr1 !== sizeStr2){
12+
return false;
13+
}
14+
15+
let arr1 = str1.toLowerCase();
16+
let arr2 = str2.toLowerCase();
17+
18+
let char1 = arr1.split('');
19+
let char2 = arr2.split('');
20+
21+
char1.sort();
22+
char2.sort();
23+
24+
25+
for(let i = 0; i < sizeStr1; i++){
26+
if(char1[i] !== char2[i]){
27+
return false;
28+
}
29+
}
30+
return true;
931
}
1032

1133
module.exports = isAnagram;

01-js/easy/expenditure-analysis.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,26 @@
1414
*/
1515

1616
function calculateTotalSpentByCategory(transactions) {
17-
return [];
18-
}
1917

20-
module.exports = calculateTotalSpentByCategory;
18+
const categoryTotal = {};
19+
20+
transactions.forEach(function(transaction){
21+
const {category, price} = transaction;
22+
23+
if(!categoryTotal[category]){
24+
categoryTotal[category] = price;
25+
}
26+
else{
27+
categoryTotal[category] += price;
28+
}
29+
});
30+
31+
const res = Object.keys(categoryTotal).map(category=>({
32+
category,
33+
totalSpent : categoryTotal[category],
34+
}));
35+
36+
return res;
37+
38+
}
39+
module.exports = calculateTotalSpentByCategory;

01-js/easy/findLargestElement.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
*/
77

88
function findLargestElement(numbers) {
9-
9+
let largest = numbers[0];
10+
for(let i = 0;i < numbers.length ;i++){
11+
if(numbers[i] > largest)
12+
largest=numbers[i];
13+
}
14+
return largest;
1015
}
1116

1217
module.exports = findLargestElement;

01-js/hard/calculator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
*/
1818

1919
class Calculator {}
20-
20+
2121
module.exports = Calculator;

01-js/medium/countVowels.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
*/
77

88
function countVowels(str) {
9-
// Your code here
9+
let char=str.toLowerCase();
10+
let count=0;
11+
for(let i=0;i<str.length;i++){
12+
if(char[i]=='a' || char[i]=='e' || char[i]=='i' || char[i]=='o' || char[i]=='u'){
13+
count++;
14+
}
15+
}
16+
return count;
1017
}
1118

1219
module.exports = countVowels;

01-js/medium/palindrome.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,45 @@
33
Note: the input string is case-insensitive which means 'Nan' is a palindrom as 'N' and 'n' are considered case-insensitive.
44
*/
55

6-
function isPalindrome(str) {
6+
function valid(ch){
7+
if(ch>='a' && ch<='z' || ch>='A' && ch<='Z' || ch<=9 && ch>=1){
8+
return true;
9+
}
10+
return false;
11+
}
12+
13+
14+
function palindrom(newStr){
15+
let start=0;
16+
let end=newStr.length-1;
17+
18+
while(start<=end){
19+
if(newStr[start]!==newStr[end]){
20+
return false;
21+
}
22+
else{
23+
start++;
24+
end--;
25+
}
26+
}
727
return true;
828
}
929

30+
//given function
31+
function isPalindrome(str) {
32+
//remove faltu characters
33+
let newStr="";
34+
35+
for(let i=0;i<str.length;i++){
36+
if(valid(str[i])){
37+
newStr += str[i];
38+
}
39+
}
40+
41+
let ch1=newStr.toLowerCase();
42+
43+
44+
return palindrom(ch1);
45+
}
46+
1047
module.exports = isPalindrome;

01-js/medium/times.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ There is no automated test for this one, this is more for you to understand time
99
*/
1010

1111
function calculateTime(n) {
12+
1213
return 0.01;
1314
}

0 commit comments

Comments
 (0)