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

Completed-week3 #1157

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
11 changes: 10 additions & 1 deletion 01-js/easy/anagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

function isAnagram(str1, str2) {

}
let newStr1= str1.toLowerCase().split("").sort().join("");
let newStr2= str2.toLowerCase().split("").sort().join("");
if(newStr1===newStr2){
return true;
}
else{
return false;
}

}
isAnagram("showkat", "akwohst")
module.exports = isAnagram;
3 changes: 2 additions & 1 deletion 01-js/easy/expenditure-analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
*/

function calculateTotalSpentByCategory(transactions) {
return [];
const categoryTotals = {};

}

module.exports = calculateTotalSpentByCategory;
7 changes: 6 additions & 1 deletion 01-js/easy/findLargestElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
  - Output: 9
*/


function findLargestElement(numbers) {

if(numbers.length==0){
return undefined;
}
let highest = Math.max(...numbers);
return highest;
}

module.exports = findLargestElement;
35 changes: 34 additions & 1 deletion 01-js/hard/calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,40 @@

Once you've implemented the logic, test your code by running
*/
const math = require("mathjs")

class Calculator {}
class Calculator {
constructor (){
this.result =0;
}
add(n){
this.result = this.result + n
}
subtract (n){
this.result = this.result - n
}
multiply (n){
this.result = this.result * n
}
divide(n){
if (n == 0){
throw new Error("its undefined")
} else {
this.result = this.result / parseFloat(n)
}
}
clear (){
this.result = 0
}
getResult (){
return this.result
}
calculate (str){
this.result= math.evaluate(str)
if (this.result== Infinity){
throw new Error("invalid expression")
}
}
}

module.exports = Calculator;
34 changes: 34 additions & 0 deletions 01-js/hard/todo-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,41 @@
*/

class Todo {
constructor(todos){
this.todos = [];
}

add(todo){
this.todos.push(todo)
}

remove(index){
if(index>= 0 && index<this.todos.length){
this.todos.splice(index, 1);
}
}

update(index, newTodo){
if(index>= 0 && index<this.todos.length){
this.todos[index] = newTodo
}
}

getAll(){
return this.todos
}

get(index){
if(index>= 0 && index<this.todos.length){
return this.todos[index]
} else{
return null
}
}

clear(){
this.todos.length = 0
}
}

module.exports = Todo;
15 changes: 14 additions & 1 deletion 01-js/medium/countVowels.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@
*/

function countVowels(str) {
// Your code here
// to count vowels
let noofvows =0;
// converting string into array for iteration and making it lowercase for case-sensitivity
let arrified = str.toLowerCase().split("");
// iterating over array
for(let i=0; i<arrified.length; i++){
// checking if the string contains aeiou
if(arrified[i]== "a" || arrified[i]=="e" ||arrified[i] =="i" ||arrified[i]== "o" || arrified[i]=="u"){
// then add 1 to noofvows which was initiated with 0
noofvows= noofvows + 1;
}
}
// returning the no of vowels
return noofvows;
}

module.exports = countVowels;
7 changes: 7 additions & 0 deletions 01-js/medium/palindrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
*/

function isPalindrome(str) {
let str1= str.toLowerCase().replace(/[^a-z0-9]/g, "");
let str2 = str.toLowerCase().split("").reverse().join("").replace(/[^a-z0-9]/g, "");
if(str1 == str2){
return true;
}
else{
return false;
}
}

module.exports = isPalindrome;
13 changes: 11 additions & 2 deletions 01-js/medium/times.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,14 @@ There is no automated test for this one, this is more for you to understand time
*/

function calculateTime(n) {
return 0.01;
}
let before =new Date().getTime();
for(let i=0; i<n; i++){
let sum = 0;
sum = sum + i;
}
let after = new Date().getTime();
let timeItTook= (after - before)/1000;
return timeItTook;
}

console.log(calculateTime(1000000))
171 changes: 170 additions & 1 deletion 01-js/package-lock.json

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

5 changes: 4 additions & 1 deletion 01-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
},
"keywords": [],
"author": "",
"license": "ISC"
"license": "ISC",
"dependencies": {
"mathjs": "^13.2.0"
}
}
2 changes: 0 additions & 2 deletions week-2/01-async-js/.gitignore

This file was deleted.

19 changes: 18 additions & 1 deletion week-2/01-async-js/easy/1-counter.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
## Create a counter in JavaScript

We have already covered this in the second lesson, but as an easy recap try to code a counter in Javascript
It should go up as time goes by in intervals of 1 second
It should go up as time goes by in intervals of 1 second.


let count = 0

console.log(count)

function counter() {
let countt = setInterval(() => {
console.log(++count)
if (count >= 10) {
clearInterval(countt)
}
}, 1000)
}


counter()
Loading