diff --git a/Nguyen-Kevin-JS-Leet-Practice/longestSubstring.js b/Nguyen-Kevin-JS-Leet-Practice/longestSubstring.js new file mode 100644 index 0000000..25e1840 --- /dev/null +++ b/Nguyen-Kevin-JS-Leet-Practice/longestSubstring.js @@ -0,0 +1,17 @@ +function lengthOfLongestSubstring(s) { + let windowCharsMap = {}; + let windowStart = 0; + let maxLength = 0; + + for (let i =0; i < s.length; i++) { + const endChar = s[i]; + + if(windowCharsMap[endChar] >= windowStart) { + windowStart = windowCharsMap[endChar] + 1; + } + + windowCharsMap[endChar] = i; + maxLength = Math.max(maxLength, i - windowStart + 1); + } + return maxLength; +} \ No newline at end of file diff --git a/Nguyen-Kevin-JS-Leet-Practice/palindrome.js b/Nguyen-Kevin-JS-Leet-Practice/palindrome.js new file mode 100644 index 0000000..a0f1fb3 --- /dev/null +++ b/Nguyen-Kevin-JS-Leet-Practice/palindrome.js @@ -0,0 +1,17 @@ + +function isParlindrome(s){ + s =s.toLowerCase().replace(/[^\w]/g, ""); + + let left = 0; + let right = s.length -1; + + while(left < right) { + if (s[left] !== s[right]){ + return false; + } + left++; + right--; + } + return true; +} + diff --git a/Traub-Eric-JS-Practice/10_use_strict.js b/Traub-Eric-JS-Practice/10_use_strict.js new file mode 100644 index 0000000..d5024d5 --- /dev/null +++ b/Traub-Eric-JS-Practice/10_use_strict.js @@ -0,0 +1,44 @@ +// example 1 + +/* require let, var, const + for variable declaration +*/ + +'use strict'; + +city = 'London'; +console.log(city); + + + + +// example 2 + +/* +parameters must be unique + +*/ + +'use strict'; + +function myFunc(a, a, b) { + console.log(a, a, b); +} +myFunc(1, 2, 3); + + + + +// example 3 + +/* +errors thrown for attempts to delete +native definitions +*/ + +'use strict'; + +delete Object.prototype; + + +// use strict: fail FAST & fail LOUDLY \ No newline at end of file diff --git a/Traub-Eric-JS-Practice/11_curry_function.js b/Traub-Eric-JS-Practice/11_curry_function.js new file mode 100644 index 0000000..4f2a950 --- /dev/null +++ b/Traub-Eric-JS-Practice/11_curry_function.js @@ -0,0 +1,32 @@ +// tab 1 + +// function getProduct(num1, num2) { +// return num1 * num2; +// } + +function getProduct(num1) { + return function(num2) { + return num1 * num2; + }; +} + +getProduct(10)(20); + + + + +// tab 2 + +// function getTravelTime(distance, speed) { +// return distance / speed; +// } + +function getTravelTime(distance) { + return function(speed) { + return distance / speed; + }; +} + +const travelTimeBosNyc = getTravelTime(400); +const travelTimeMiamiAtlanta = getTravelTime(600); +console.log(travelTimeBosNyc(100)); \ No newline at end of file diff --git a/Traub-Eric-JS-Practice/12_counter_function.js b/Traub-Eric-JS-Practice/12_counter_function.js new file mode 100644 index 0000000..c672cd3 --- /dev/null +++ b/Traub-Eric-JS-Practice/12_counter_function.js @@ -0,0 +1,20 @@ +function myFunc() { + let count = 0; + + return function() { + count++; + return count; + }; + } + + console.log(myFunc()); + + const instanceOne = myFunc(); + const instanceTwo = myFunc(); + + console.log('instanceOne: ', instanceOne()); + console.log('instanceOne: ', instanceOne()); + console.log('instanceOne: ', instanceOne()); + console.log('instanceTwo: ', instanceTwo()); + console.log('instanceTwo: ', instanceTwo()); + console.log('instanceOne: ', instanceOne()); \ No newline at end of file diff --git a/Traub-Eric-JS-Practice/13_logging_x_and_y.js b/Traub-Eric-JS-Practice/13_logging_x_and_y.js new file mode 100644 index 0000000..fa0764b --- /dev/null +++ b/Traub-Eric-JS-Practice/13_logging_x_and_y.js @@ -0,0 +1,8 @@ +"use strict"; + +(function() { + var x = y = 200; +})(); + +console.log('y: ', y); +console.log('x: ', x); \ No newline at end of file diff --git a/Traub-Eric-JS-Practice/14_call_and_apply.js b/Traub-Eric-JS-Practice/14_call_and_apply.js new file mode 100644 index 0000000..2db210d --- /dev/null +++ b/Traub-Eric-JS-Practice/14_call_and_apply.js @@ -0,0 +1,18 @@ +const car1 = { + brand: 'Porsche', + getCarDescription: function(cost, year, color) { + console.log(`This car is a ${this.brand}. The price is $${cost}. The year is ${year}. The color is ${color}.\n`); + } +}; + +const car2 = { + brand: 'Lamborghini' +}; + +const car3 = { + brand: 'Ford' +}; + +car1.getCarDescription(80000, 2010, 'blue'); +car1.getCarDescription.call(car2, 200000, 2013, 'yellow'); +car1.getCarDescription.apply(car3, [35000, 2012, 'black']); \ No newline at end of file diff --git a/Traub-Eric-JS-Practice/15_determine_list2.js b/Traub-Eric-JS-Practice/15_determine_list2.js new file mode 100644 index 0000000..dbe3a31 --- /dev/null +++ b/Traub-Eric-JS-Practice/15_determine_list2.js @@ -0,0 +1,8 @@ +const list1 = [1, 2, 3, 4, 5]; +const list2 = list1.slice(); +// const list2 = list1.concat([]); + +list1.push(6, 7, 8); + +console.log('List 1: ', list1); +console.log('List 2: ', list2); \ No newline at end of file diff --git a/Traub-Eric-JS-Practice/16_singly_doubly_invoked_functions.js b/Traub-Eric-JS-Practice/16_singly_doubly_invoked_functions.js new file mode 100644 index 0000000..901eeaa --- /dev/null +++ b/Traub-Eric-JS-Practice/16_singly_doubly_invoked_functions.js @@ -0,0 +1,17 @@ +function getTotal() { + var args = Array.prototype.slice.call(arguments); + + if (args.length === 2) { + return args[0] + args[1]; + } + else if (args.length === 1) { + return function(num2) { + return args[0] + num2; + }; + } + } + + console.log(getTotal(10, 20)); + console.log(getTotal(5, 40)); + console.log(getTotal(3)(30)); + console.log(getTotal(8)(12)); \ No newline at end of file diff --git a/Traub-Eric-JS-Practice/17_json_data.js b/Traub-Eric-JS-Practice/17_json_data.js new file mode 100644 index 0000000..722ed53 --- /dev/null +++ b/Traub-Eric-JS-Practice/17_json_data.js @@ -0,0 +1,17 @@ +// TASK: +// 1. Describe what JSON format is. +// 2. Delete the data types not permitted in JSON. +// 3. Replace placeholder-text with the corresponding data type, +// properly formatted as JSON. + +const myJsonObj = { + "myString": "hello world", + "myNumber": 12345.6789, + "myNull": null, + "myBoolean": true, + "myArray": [20, 30, "orange"], + "myObject": { + "name": "Sam", + "age": 30 + } + }; \ No newline at end of file diff --git a/Traub-Eric-JS-Practice/18_order_logged_out.js b/Traub-Eric-JS-Practice/18_order_logged_out.js new file mode 100644 index 0000000..2666ce6 --- /dev/null +++ b/Traub-Eric-JS-Practice/18_order_logged_out.js @@ -0,0 +1,8 @@ +function logNumbers() { + console.log(1); + setTimeout(function(){console.log(2)}, 1000); + setTimeout(function(){console.log(3)}, 0); + console.log(4); +} + +logNumbers(); \ No newline at end of file diff --git a/Traub-Eric-JS-Practice/19_creating_objects.js b/Traub-Eric-JS-Practice/19_creating_objects.js new file mode 100644 index 0000000..ded5ef3 --- /dev/null +++ b/Traub-Eric-JS-Practice/19_creating_objects.js @@ -0,0 +1,38 @@ +// object literal syntax +const myBoat = { + length: 24, + maxSpeed: 45, + passengers: 14, + getLength: function() { + return this.length; + } + }; + + + // new keyword & Object constructor + const student = new Object(); + + student.grade = 12; + student.gradePointAverage = 3.7; + student.classes = ["English", "Algebra", "Chemistry"]; + student.getClasses = function() { + return this.classes; + }; + + + // constructor function + function Car(color, brand, year) { + this.color = color; + this.brand = brand; + this.year = year; + } + + Car.prototype.getColor = function() { + return this.color; + }; + + const carlysCar = new Car('blue', 'ferarri', 2015); + const jimsCar = new Car('red', 'tesla', 2014); + + console.log(carlysCar.getColor()); + console.log(jimsCar.getColor()); \ No newline at end of file diff --git a/Traub-Eric-JS-Practice/1_tripleAdd.js b/Traub-Eric-JS-Practice/1_tripleAdd.js new file mode 100644 index 0000000..73920b1 --- /dev/null +++ b/Traub-Eric-JS-Practice/1_tripleAdd.js @@ -0,0 +1,9 @@ +tripleAdd(10)(20)(30); // 60 + +function tripleAdd(num1) { + return function(num2) { + return function(num3) { + return num1 + num2 + num3; + } + } +} diff --git a/Traub-Eric-JS-Practice/20_typeof_data_types.js b/Traub-Eric-JS-Practice/20_typeof_data_types.js new file mode 100644 index 0000000..8fd20c6 --- /dev/null +++ b/Traub-Eric-JS-Practice/20_typeof_data_types.js @@ -0,0 +1,6 @@ +console.log(typeof null); +console.log(typeof undefined); +console.log(typeof {}); +console.log(typeof []); +console.log(Array.isArray([])); +console.log([] instanceof Array); \ No newline at end of file diff --git a/Traub-Eric-JS-Practice/2_iife.js b/Traub-Eric-JS-Practice/2_iife.js new file mode 100644 index 0000000..356033e --- /dev/null +++ b/Traub-Eric-JS-Practice/2_iife.js @@ -0,0 +1,7 @@ +// immediately invoked function + +(function doubleNumber(num){ + return num * 2; +})(10); + +doubleNumber(5); \ No newline at end of file diff --git a/Traub-Eric-JS-Practice/3_button_5.js b/Traub-Eric-JS-Practice/3_button_5.js new file mode 100644 index 0000000..4904551 --- /dev/null +++ b/Traub-Eric-JS-Practice/3_button_5.js @@ -0,0 +1,56 @@ +// function createButtons() { +// for (var i = 1; i <= 5; i++) { +// var body = document.getElementsByTagName("BODY")[0]; +// var button = document.createElement("BUTTON"); +// button.innerHTML = 'Button ' + i; +// button.onclick = function() { +// alert('This is button ' + i); +// } +// body.appendChild(button); +// } +// } + +// createButtons(); + + // Solution 2: + +function createButtons() { + for (var i = 1; i <= 5; i++) { + var body = document.getElementsByTagName("BODY")[0]; + var button = document.createElement("BUTTON"); + button.innerHTML = 'Button ' + i; + // (function(num) { + // button.onclick = function() { + // alert('This is button ' + num); + // }; + // })(i) + addClickFunctionality(button, i); + body.appendChild(button); + } + } + + createButtons(); + + + function addClickFunctionality(button, num) { + button.onclick = function() { + alert('This is button ' + num); + } + } + + // Solution 3: + // let is block scoped instead of function scoped + +function createButtons() { + for (let i = 1; i <= 5; i++) { + var body = document.getElementsByTagName("BODY")[0]; + var button = document.createElement("BUTTON"); + button.innerHTML = 'Button ' + i; + button.onclick = function() { + alert('This is button ' + i); + } + body.appendChild(button); + } + } + + createButtons(); \ No newline at end of file diff --git a/Traub-Eric-JS-Practice/4_closure.js b/Traub-Eric-JS-Practice/4_closure.js new file mode 100644 index 0000000..e69de29 diff --git a/Traub-Eric-JS-Practice/5_this.js b/Traub-Eric-JS-Practice/5_this.js new file mode 100644 index 0000000..e69de29 diff --git a/Traub-Eric-JS-Practice/7_self.js b/Traub-Eric-JS-Practice/7_self.js new file mode 100644 index 0000000..8d4966c --- /dev/null +++ b/Traub-Eric-JS-Practice/7_self.js @@ -0,0 +1,22 @@ +var myCar = { + color: "Blue", + logColor: function() { + var self = this; + console.log("In logColor - this.color: " + this.color); + console.log("In logColor - self.color: " + self.color); + (function() { + console.log("In IIFE - this.color: " + this.color); + console.log("In IIFE - self.color: " + self.color); + })(); + } +}; + +myCar.logColor(); + + +/* +blue +blue +undefined +blue +*/ \ No newline at end of file diff --git a/Traub-Eric-JS-Practice/8_equals_vs_strict.js b/Traub-Eric-JS-Practice/8_equals_vs_strict.js new file mode 100644 index 0000000..3c1c954 --- /dev/null +++ b/Traub-Eric-JS-Practice/8_equals_vs_strict.js @@ -0,0 +1,15 @@ +console.log(7 == '7'); // true + +console.log(7 === '7'); // false + + +/* +== + +num == str // string converted to num + +boolean == non-boolean // non-boolean converted to boolean + +object == primitive // object converted to primitive + +*/ \ No newline at end of file diff --git a/Traub-Eric-JS-Practice/9_log_numer.js b/Traub-Eric-JS-Practice/9_log_numer.js new file mode 100644 index 0000000..016e719 --- /dev/null +++ b/Traub-Eric-JS-Practice/9_log_numer.js @@ -0,0 +1,8 @@ +var num = 50; + +function logNumber() { + console.log(num); + var num = 100; +} + +logNumber(); \ No newline at end of file diff --git a/Traversy_Brad_Modern_JS/index.html b/Traversy_Brad_Modern_JS/index.html new file mode 100644 index 0000000..f15b337 --- /dev/null +++ b/Traversy_Brad_Modern_JS/index.html @@ -0,0 +1,13 @@ + + +
+ + +