Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
0f79e81
first exercise complated
agodse21 Apr 4, 2023
ddc9c99
second exercise complated
agodse21 Apr 4, 2023
7317309
Third Exercise complated
agodse21 Apr 5, 2023
c090afc
Fourth exercise complated
agodse21 Apr 5, 2023
c637a9b
Fifth exercise complated
agodse21 Apr 5, 2023
407f756
Sixth exercise complated
agodse21 Apr 5, 2023
3e77888
Seventh exercise complated
agodse21 Apr 5, 2023
ad7bc7d
8th exercise complated
agodse21 Apr 5, 2023
1737a21
9th exercise complated
agodse21 Apr 5, 2023
091fbd4
10th exercise complated
agodse21 Apr 5, 2023
624b13c
11th exercise complated
agodse21 Apr 5, 2023
dcd16d8
12th exercise complated
agodse21 Apr 5, 2023
96d8421
13th exercise compalted
agodse21 Apr 5, 2023
0f44258
14th exercise complated
agodse21 Apr 5, 2023
c13124b
15th exercise complated
agodse21 Apr 5, 2023
c57858b
16th exercise complated
agodse21 Apr 5, 2023
0d23c13
17th exercise complated
agodse21 Apr 5, 2023
bcf4e5c
18th exercise complated
agodse21 Apr 5, 2023
c732e68
19th exercise complated
agodse21 Apr 5, 2023
361b1e0
20th exercise complated
agodse21 Apr 5, 2023
28aac64
21th exercise complated
agodse21 Apr 5, 2023
72d0cf5
22th exercise complated
agodse21 Apr 5, 2023
9839a0d
23th exercise complated
agodse21 Apr 5, 2023
b0032be
24th exercise complated
agodse21 Apr 5, 2023
1fc4e91
25th exercise complated
agodse21 Apr 5, 2023
2a9effd
26th exercise complated
agodse21 Apr 5, 2023
c1a2cd1
27th exercise complated
agodse21 Apr 5, 2023
731218d
28th exercise complated
agodse21 Apr 5, 2023
e9248ee
29th exercise complated
agodse21 Apr 5, 2023
98e83ea
30th exercise complated
agodse21 Apr 5, 2023
2d804a5
30th exercise complated
agodse21 Apr 5, 2023
d2cfae0
31th exercise complated
agodse21 Apr 6, 2023
d4da1ce
32th exercise complated
agodse21 Apr 6, 2023
84570bd
33th exercise complated
agodse21 Apr 6, 2023
5ee6aa5
34th exercise complated
agodse21 Apr 6, 2023
d7ab1a6
35th exercise complated
agodse21 Apr 6, 2023
8b60cff
23th exercise updated and 36th execise complated
agodse21 Apr 6, 2023
41d0d94
22th exercise updated
agodse21 Apr 6, 2023
699c496
updated with test case
agodse21 Apr 6, 2023
3e2f7da
updated files
agodse21 Apr 6, 2023
9f35614
updated with test cases
agodse21 Apr 6, 2023
e102936
updated exercise 3 with test cases
agodse21 Apr 6, 2023
5e54b7f
updated exercise 3 with test cases
agodse21 Apr 6, 2023
3de928b
updated exercise 4 with test cases
agodse21 Apr 6, 2023
8b46a7f
updated exercise 5 with test cases
agodse21 Apr 6, 2023
82a49bf
updated exercise 6 with testcases
agodse21 Apr 6, 2023
79dbe0d
exercise 7 to 10 complated with testcases
agodse21 Apr 8, 2023
42ad7aa
exercise 11 to 12 complated with testcases
agodse21 Apr 8, 2023
01229ec
exercise 13 to 14 complated with testcases
agodse21 Apr 8, 2023
b66939d
exercise 15complated with testcases& exercise 16 updated
agodse21 Apr 8, 2023
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
1 change: 1 addition & 0 deletions src/exercises/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
11 changes: 9 additions & 2 deletions src/exercises/1/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
// - comment the reason for failure.
// - Fix the issue.

// ans: In for loop you use const variable and const is constant we can't change thier value so i have changed const to let.
// Variables defined with const cannot be Redeclared.
// Variables defined with const cannot be Reassigned.
// Variables defined with const have Block Scope.

function printOneToTen() {
for (const number = 1; number <= 10; number++) {
console.log(`\n${number}`);
for (let number = 1; number <= 10; number++) {
console.log(number);
}
}

module.exports = printOneToTen;
11 changes: 11 additions & 0 deletions src/exercises/1/exercise.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const printOneToTen = require("./exercise.js");
describe("Use of loop", () => {
test("Print 1 to 10 in new line", () => {
const consoleSpy = jest.spyOn(console, "log").mockImplementation();
printOneToTen();
expect(consoleSpy).toHaveBeenCalledTimes(10);
expect(consoleSpy).toHaveBeenNthCalledWith(1, 1);
expect(consoleSpy).toHaveBeenNthCalledWith(10, 10);
consoleSpy.mockRestore();
});
});
19 changes: 18 additions & 1 deletion src/exercises/10/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,21 @@
}
]
*/
function findVoteEligibleCandidates(populationList) {}

//method 1
// function findVoteEligibleCandidates(populationList) {
// const eligibleCandidates = populationList.filter((ele) => ele.age >= 18);
// eligibleCandidates.map((ele) => {
// console.log(ele.name);
// });
// }

//method 2

function findVoteEligibleCandidates(populationList) {
populationList.map((Candidates) => {
Candidates.age >= 18 && console.log(Candidates.name);
});
}

module.exports = findVoteEligibleCandidates;
20 changes: 20 additions & 0 deletions src/exercises/10/exercise.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const findVoteEligibleCandidates = require("./exercise.js");

describe("Use of array methods", () => {
it("should Print the names of the candidates eligible to vote", () => {
const consoleSpy = jest.spyOn(console, "log");
const input = [
{
name: "Ravi",
age: 28,
},
{
name: "Teja",
age: 28,
},
];
findVoteEligibleCandidates(input);
expect(consoleSpy).toHaveBeenCalledWith("Ravi");
expect(consoleSpy).toHaveBeenCalledWith("Teja");
});
});
9 changes: 8 additions & 1 deletion src/exercises/11/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@
// - Use Array methods
// - Do not use loops

function sumOfArray(inputArray) {}
//Ans: Used reduce() array method to sum of all the elements in the array

function sumOfArray(inputArray) {
const sum = inputArray.reduce((acc, currentVal) => acc + currentVal, 0);
console.log(`Sum of the elements in the given array is ${sum}`);
}

module.exports = sumOfArray;
12 changes: 12 additions & 0 deletions src/exercises/11/exercise.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const sumOfArray = require("./exercise.js");

describe("Use of array reduce methods", () => {
it("should print the sum of the elements in the given array", () => {
const consoleSpy = jest.spyOn(console, "log");
const input = [1, 2, 3, 5];
sumOfArray(input);
expect(consoleSpy).toHaveBeenCalledWith(
"Sum of the elements in the given array is 11"
);
});
});
9 changes: 7 additions & 2 deletions src/exercises/12/exercise.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// Gracefully handle the error in the errorCaller function

function errorFunction() {
throw "This is a random error";
throw new Error("This is a random error");
}

function errorCaller() {
errorFunction();
try {
errorFunction();
} catch (err) {
console.log(err);
}
}
module.exports = errorFunction;
7 changes: 7 additions & 0 deletions src/exercises/12/exercise.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

const errorFunction = require("./exercise.js");
describe("Handle Errors", () => {
it("should handle error or not", () => {
expect(() => errorFunction()).toThrow(Error);
});
});
14 changes: 12 additions & 2 deletions src/exercises/13/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ const employee = {
lastName: "Teja",
age: 29,
id: 1122,
getFullName: function () {},
checkVoteEligiblity: function () {},
getFullName: function () {
console.log(`${this.firstName} ${this.lastName}`);
},
checkVoteEligiblity: function () {
if (this.age >= 18) {
console.log("You are eligible to vote.");
} else {
console.log("You are not eligible to vote.");
}
},
};

module.exports = employee;
18 changes: 18 additions & 0 deletions src/exercises/13/exercise.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const employee = require("./exercise.js");

describe("Object concepts", () => {
it("should print the fullname of employee", () => {
const consoleSpy = jest.spyOn(console, "log");
employee.getFullName();
expect(consoleSpy).toHaveBeenCalledWith("Ravi Teja");
});
it("should print the Vote Eligiblity", () => {
const consoleSpy = jest.spyOn(console, "log");
employee.checkVoteEligiblity();
if (employee.age >= 18) {
expect(consoleSpy).toHaveBeenCalledWith("You are eligible to vote.");
} else {
expect(consoleSpy).toHaveBeenCalledWith("You are not eligible to vote.");
}
});
});
8 changes: 7 additions & 1 deletion src/exercises/14/exercise.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
// Get the full name of the new employee. See how you can execute the function "getFullName" on newEmployee object.
// - Comment your findings

//Ans: In the example, when we call employee.getFullName, the value of this will be bound to object newEmployee, even when getFullName is not a method of newEmployee.

const employee = {
firstName: "Ravi",
lastName: "Teja",
age: 29,
id: 1122,
getFullName: function () {
//Copy the solution from the exercise before this.
return `${this.firstName} ${this.lastName}`;
},
};

const newEmployee = {
firstName: "New",
lastName: "Employee",
};
const fullName = employee.getFullName.call(newEmployee);
console.log(fullName);

module.exports = employee;
16 changes: 16 additions & 0 deletions src/exercises/14/exercise.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const employee = require("./exercise.js");

describe("Object methods", () => {
it("should return the fullname of employee", () => {
expect(employee.getFullName()).toBe("Ravi Teja");
});

it("should return the fullname of new employee", () => {
const newEmployee = {
firstName: "New",
lastName: "Employee",
};
const fullName = employee.getFullName.call(newEmployee);
expect(fullName).toBe("New Employee");
});
});
9 changes: 7 additions & 2 deletions src/exercises/15/exercise.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// Convert the below functions into arrow functions.

const greetings = function () {
const greetings = () => {
return "Hello World";
};

const isEven = function (num) {
const isEven = (num) => {
if (num % 2 == 0) {
return true;
} else {
return false;
}
};

module.exports = {
greetings,
isEven,
};
14 changes: 14 additions & 0 deletions src/exercises/15/exercise.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { isEven, greetings } = require("./exercise.js");

describe("Arrow function", () => {
it("should return greeting", () => {
expect(greetings()).toBe("Hello World");
});

it("should returns true for even number", () => {
expect(isEven(2)).toBe(true);
});
it("should returns false for odd number", () => {
expect(isEven(3)).toBe(false);
});
});
45 changes: 44 additions & 1 deletion src/exercises/16/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,48 @@
// - Create function for all the possible functionalities.

class Leave {
//...
constructor(leaveType, startDate, endDate, reason) {
this.leaveType = leaveType;
this.startDate = startDate;
this.endDate = endDate;
this.reason = reason;
this.status = "pending";
}

approve() {
this.status = "approved";
}

reject() {
this.status = "rejected";
}

cancel() {
this.status = "cancelled";
}

viewDetails() {
console.log(`
Leave Type: ${this.leaveType}
Start Date: ${this.startDate}
End Date: ${this.endDate}
Reason: ${this.reason}
Status: ${this.status}
`);
}
}

const leaveRequest = new Leave(
"sick",
"2023-04-10",
"2023-04-12",
"I have a cold"
);

// view the details of the leave request
leaveRequest.viewDetails();

// approve the leave request
leaveRequest.approve();

leaveRequest.viewDetails();
70 changes: 70 additions & 0 deletions src/exercises/17/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,71 @@
// Extend the Leave class, to create different classes for different Leave types.
class Leave {
constructor(startDate, endDate, reason) {
this.startDate = startDate;
this.endDate = endDate;
this.reason = reason;
this.status = "pending";
}

approve() {
this.status = "approved";
}

reject() {
this.status = "rejected";
}

cancel() {
this.status = "cancelled";
}

viewDetails() {
console.log(`
Start Date: ${this.startDate}
End Date: ${this.endDate}
Reason: ${this.reason}
Status: ${this.status}
`);
}
}

class SickLeave extends Leave {
constructor(startDate, endDate, reason) {
super(startDate, endDate, reason);
this.leaveType = "sick";
}

viewDetails() {
super.viewDetails();
console.log(`Leave Type: ${this.leaveType}`);
}
}

class AnnualLeave extends Leave {
constructor(startDate, endDate, reason) {
super(startDate, endDate, reason);
this.leaveType = "annual";
}

viewDetails() {
super.viewDetails();
console.log(`Leave Type: ${this.leaveType}`);
}
}

//usage
const sickLeaveRequest = new SickLeave(
"2023-04-10",
"2023-04-12",
"I have a cold"
);
sickLeaveRequest.viewDetails();

const annualLeaveRequest = new AnnualLeave(
"2023-06-01",
"2023-06-05",
"Vacation"
);
annualLeaveRequest.viewDetails();
annualLeaveRequest.approve();
annualLeaveRequest.viewDetails();
15 changes: 15 additions & 0 deletions src/exercises/18/AnnualLeave.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Leave from "./Leave.js";

class AnnualLeave extends Leave {
constructor(startDate, endDate) {
super(startDate, endDate);
this.reason = "AnualLeave";
}

viewDetails() {
super.viewDetails();
console.log(`Leave Type: ${this.reason}`);
}
}

export default AnnualLeave;
Loading