Skip to content

Commit 72a563a

Browse files
committed
update
1 parent d3e0a48 commit 72a563a

File tree

6 files changed

+41
-1
lines changed

6 files changed

+41
-1
lines changed

Oops/12_University.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class University {
1818
} else {
1919
console.log(`Department "${department}" does not exist in ${this.name}.`);
2020
}
21-
2221
}
2322
display() {
2423
console.log(`Departments in ${this.uni_name}:`);

Oops/5_shapes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// 5. Write a JavaScript program that creates a class called 'Shape' with a method to calculate the area. Create two subclasses, 'Circle' and 'Triangle', that inherit from the 'Shape' class and override the area calculation method. Create an instance of the 'Circle' class and calculate its area. Similarly, do the same for the 'Triangle' class.
2+
23
class shape {
34
calculateArea() {
45
throw new Error("Method 'calculateArea()' must be overridden in subclasses");

Oops/encapsulation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// <!-- Abstraction: Abstraction means displaying only essential information and hiding the details. Data abstraction refers to providing only essential information about the data to the outside world, hiding the background details or implementation. -->
22
// Encapsulation: The process of wrapping properties and functions within a single unit is known as encapsulation.
3+
34
// Encapsulation example
45
class person {
56
constructor(name, id) {

coding_series/15_colors_ini.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
// Write a JavaScript program to display the colors in the following way :
3+
34
const color = ["Blue ", "Green", "Red", "Orange", "Violet", "Indigo", "Yellow "];
45

56
color.forEach((colors, index) => {

coding_series/18_BinarySearch.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Binary Search
2+
function binarySearch(key, arr) {
3+
const newArr = arr.sort((a, b) => a - b)
4+
let start = 0, end = arr.length - 1;
5+
while (start <= end) {
6+
let mid = Math.floor((start + end) / 2)
7+
if (newArr[mid] === key) {
8+
return (`${key} is find at position ${mid}`)
9+
} else if (newArr[mid] < key) {
10+
start = mid + 1;
11+
} else {
12+
end = mid - 1;
13+
}
14+
}
15+
return `${key} is not found`;
16+
}
17+
18+
const arr = [3, 5, 6, 8, 9, 3, 11]
19+
console.log(binarySearch(9, arr))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// There are two arrays with individual values.Write a JavaScript program to compute the sum of each individual index value in the given array.
2+
3+
array1 = [1, 0, 2, 3, 4];
4+
array2 = [3, 5, 6, 7, 8, 13];
5+
6+
function computeSum(arr1, arr2) {
7+
const maxLength = Math.max(arr1.length, arr2.length);
8+
const newArr = [];
9+
10+
for (let i = 0; i < maxLength; i++) {
11+
const value1 = arr1[i] !== undefined ? arr1[i] : 0;
12+
const value2 = arr2[i] !== undefined ? arr2[i] : 0;
13+
newArr.push(value1 + value2);
14+
}
15+
16+
return newArr;
17+
}
18+
19+
console.log(computeSum(array1, array2));

0 commit comments

Comments
 (0)