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
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;
// 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;
};
// 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()
// 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 = {
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)
}
const countCharacters = (str) => {
const result = {};
const arr = str.split('');
for (word of arr) {
if (result[word]) {
result[word]++;
} else {
result[word] = 1;
// 5
const getLocation = (city, country = 'Italy', continent = 'Europe') =>
console.log(continent, country, city);
getLocation('Milan');
// Europe Italy Milan
getLocation('Paris', 'France');
// Europe France Paris
const name = "Francis", lastname = "Jones", age = 23;
let obj;
function createObject(name,lastname,age){
return obj = {
name,
lastname,
age,
}
}
@buymed-hoangpham
buymed-hoangpham / index.js
Created September 23, 2022 10:51
Homework
//1.
const subLength = (str, char) => {
let charInStr = [],
lowerStr = str.toLowerCase().split(''),
length = 0;
lowerStr.forEach((val, index) => {
if (val === char) {
charInStr.push(index);
}
@buymed-hoangpham
buymed-hoangpham / index.js
Created September 13, 2022 09:11
exercise
// 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));