Skip to content

Instantly share code, notes, and snippets.

View buymed-hoangpham's full-sized avatar
💻
Practice makes Perfect

Hoangthu2 buymed-hoangpham

💻
Practice makes Perfect
View GitHub Profile
// 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 = {
// 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()
// 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;
};
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;