This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let a = 5 | |
| let b = 10 | |
| function swapValue(a, b) { | |
| let temp = a | |
| a = b | |
| b = temp | |
| console.log(a); | |
| console.log(b); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Exercise 1 | |
| let input = 2 | |
| if (input % 2) { | |
| console.log('odd'); | |
| } else { | |
| console.log('even'); | |
| } | |
| // Exercise 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let nums = [1, 3, 5, 21, 56, 2, 7, 11, 15] | |
| let target = 9 | |
| function twoSum(nums, target) { | |
| let output = [] | |
| for (var i = 0; i < nums.length; i++) { | |
| output.push(i) | |
| output.push(i + 1) | |
| if (nums[output[0]] + nums[output[1]] === target) { | |
| return output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Sign of the Product of an Array. | |
| var arraySign = function(nums) { | |
| let product = 1 | |
| for (let i = 0; i < nums.length; i++) { | |
| product *= nums[i] | |
| } | |
| if (product > 0) { | |
| return 1 | |
| } else if (product < 0) { | |
| return -1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const peopleNameArray = ["William", "Collin", "Stephen"]; | |
| const showPeopleName = function (name) { | |
| console.log("Hello " + name); | |
| } | |
| peopleNameArray.forEach(showPeopleName) | |
| peopleNameArray.forEach(showPeopleName) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Challenge 1 | |
| const fName = "Vinh" | |
| const lName = "Truong" | |
| const age = 25 | |
| const profession = "FE Dev" | |
| const salary = 10 | |
| console.log(`My name is ${fName} ${lName}, i'm ${age} years old. I work as ${profession} and make ${salary}$`); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const tinhDiem = (mon1, mon2, mon3, khuVuc, doiTuong, diemChuan) => { | |
| if (mon1 ===0 || mon2 === 0 || mon3 === 0) { | |
| return 'Rớt' | |
| } | |
| let tongDiem = mon1 + mon2 + mon3 | |
| if (khuVuc === 'A') { | |
| tongDiem += 2 | |
| } else if (khuVuc === 'B') { | |
| tongDiem += 1 | |
| } else if (khuVuc === 'C') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Test 1 | |
| const subLength = (string,occurencies) => { | |
| let indexArray = [] | |
| for (let i = 0; i < string.length; i++) { | |
| (string[i] === occurencies) ? indexArray.push(i) : false | |
| } | |
| return (indexArray.length > 2 || indexArray.length < 2) ? 0 : indexArray[1] - indexArray[0] + 1 | |
| } | |
| // Test 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let person = { | |
| first: "Alberto", | |
| last: "Montalesi" | |
| } | |
| const {first , last} = person | |
| console.log(first,last); | |
| const { facebook } = { | |
| ...person, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Exercise 1 | |
| const indexOf = (arr, item) => { | |
| let output | |
| if (!arr.includes(item)) { output = -1 } | |
| for (const i in arr) { | |
| (arr[i] === item) ? output = i : false | |
| } | |
| return output | |
| } | |
| console.log(indexOf([1, 2, 3, 4], 3)) |
OlderNewer