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 _ = { | |
| clamp(number, lower, upper) { | |
| const lowerClampedValue = Math.max(number, lower); | |
| const clampedValue = Math.min(lowerClampedValue, upper); | |
| return clampedValue; | |
| }, | |
| inRange(number, start, end) { | |
| if (end === undefined) { end = start, start = 0 } | |
| if (start > end) { [start, end] = [end, start] } |
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
| type Restaurant = { | |
| name: string; | |
| priceBracket: PriceBracket; | |
| deliveryTimeMinutes: number; | |
| openHour: number; | |
| closeHour: number; | |
| distance: number; | |
| }; | |
| type Order = { |
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
| // Returns a random DNA base | |
| const returnRandBase = (takenBase) => { | |
| const dnaBases = ["A", "T", "C", "G"]; | |
| if (takenBase) { | |
| dnaBases.splice(dnaBases.indexOf(takenBase),1) | |
| } | |
| return dnaBases[Math.floor(Math.random() * dnaBases.length)]; | |
| }; | |
| // Returns a random single strand of DNA containing 15 bases |
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)) |
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
| // 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
| 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
| // 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 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
| // 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 |