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) { | |
| end = start; | |
| start = 0; |
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
| // 1. Test your concepts of arrays by determining the location of an item in an array. | |
| const indexOf = (arr, item) => { | |
| // Your code here | |
| for (let i = 0; i < arr.length; i++) { | |
| if (arr[i] === item) return i; | |
| } | |
| 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
| // 1 type Point = {x: number, y: number}; | |
| type Point = {x: number, y: number} | |
| // 2 let coors: Point[] = [] | |
| let coors: Point[] = [] | |
| // 3 write a function in order to generate default Point => {x: 0, y: 0} generateOriginalPoint() | |
| const generateOriginalPoint = (): Point => ({x: 0, y: 0}) | |
| // 4 write a function in order to generate a random Point => {x: random, y: random} generateRandomPoint() |
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
| // Write the Movie type alias to make the following two variables properly typed | |
| // Make sure that "originalTitle" is optional and "title" is readonly | |
| type BoxOffice = { | |
| budget: number; | |
| grossUS: number; | |
| grossWorldwide: number; | |
| } | |
| type Movie = { |
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
| function twoFer(name: string = "you"): string { | |
| return `One for ${name}, one for me` | |
| } | |
| console.log(twoFer()) | |
| console.log(twoFer("Elton")) | |
| function isLeapYear(year: number): boolean { | |
| return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0) | |
| } |
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 countCharacters = (str) => { | |
| const result = {}; | |
| const arr = str.split(''); | |
| for (word of arr) { | |
| if (result[word]) { | |
| result[word]++; | |
| } else { | |
| result[word] = 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
| // 5 | |
| const getLocation = (city, country = 'Italy', continent = 'Europe') => | |
| console.log(continent, country, city); | |
| getLocation('Milan'); | |
| // Europe Italy Milan | |
| getLocation('Paris', 'France'); | |
| // Europe France Paris |
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 name = "Francis", lastname = "Jones", age = 23; | |
| let obj; | |
| function createObject(name,lastname,age){ | |
| return obj = { | |
| name, | |
| lastname, | |
| age, | |
| } | |
| } |
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
| //1. | |
| const subLength = (str, char) => { | |
| let charInStr = [], | |
| lowerStr = str.toLowerCase().split(''), | |
| length = 0; | |
| lowerStr.forEach((val, index) => { | |
| if (val === char) { | |
| charInStr.push(index); | |
| } |
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
| // 9. | |
| const removeEven = (arr) => { | |
| return arr.filter((el) => el % 2 !== 0); | |
| }; | |
| console.log(removeEven([1, 2, 4, 5, 10, 6, 3])); | |
| // 10. | |
| const capitalize = (words) => { | |
| return words.map((el) => el.charAt(0).toUpperCase() + el.slice(1)); |
NewerOlder