Skip to content

Commit ec75927

Browse files
committed
updated to es6
1 parent e6fed13 commit ec75927

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

01 - JavaScript-Basics/Arrays.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Initialize new array
2-
var names = ['John', 'Mark', 'Jane'];
3-
var years = new Array(1990, 1969, 1948);
2+
let names = ['John', 'Mark', 'Jane'];
3+
let years = new Array(1990, 1969, 1948);
44

55
console.log(names[2]); // Jane
66
console.log(names.length); // 3
@@ -11,7 +11,7 @@ names[names.length] = 'Mary';
1111
console.log(names);
1212

1313
// Different data types
14-
var john = ['John', 'Smith', 1990, 'designer', false];
14+
let john = ['John', 'Smith', 1990, 'designer', false];
1515

1616
john.push('blue'); // last input
1717
john.unshift('Mr.'); // first input
@@ -25,5 +25,5 @@ console.log(john);
2525
console.log(john.indexOf(23)); // -1 [because there is no such index.]
2626

2727
// Ternary Operator
28-
var isDesigner = john.indexOf('designer') === -1 ? 'John is NOT a designer' : 'John IS a designer';
28+
let isDesigner = john.indexOf('designer') === -1 ? 'John is NOT a designer' : 'John IS a designer';
2929
console.log(isDesigner); // John IS a designer

01 - JavaScript-Basics/Functions2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
// Function expression
11-
var whatDoYouDo = function (job, firstName) {
11+
const whatDoYouDo = (job, firstName) => {
1212
switch (job) {
1313
case 'teacher':
1414
return firstName + ' teaches kids how to code';

01 - JavaScript-Basics/emailValidate.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
function validateEmail(email) {
1+
// email regex
2+
const validateEmail = (email) => {
23
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
34
return re.test(String(email).toLowerCase());
45
}

algorithms/binarySearchRecursive.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
function binarySearch(arr, val, start = 0, end = arr.length - 1) {
1+
const binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
22
const mid = Math.floor((start + end) / 2);
33

4-
if (val === arr[mid]) {
5-
return mid;
6-
}
4+
if (val === arr[mid]) return mid;
75

8-
if (start >= end) {
9-
return -1;
10-
}
6+
if (start >= end) return -1;
117

128
return val < arr[mid]
139
? binarySearch(arr, val, start, mid - 1)
1410
: binarySearch(arr, val, mid + 1, end);
15-
}
11+
};
1612

17-
let arr = [1, 2, 4, 6, 100, 10000];
13+
const arr = [1, 9, 5, 7, 2, 4, 8, 6].sort();
1814

19-
console.log(binarySearch(arr, 2));
15+
const result = binarySearch(arr, 2);
16+
17+
console.log(result !== -1 ? `Element is present at index ${result}` : 'Element is not present in array');

0 commit comments

Comments
 (0)