//input: typeof num === number
//output: Array<number>
function countBy(num) {
const multiples = [];
for(let i = 1; i <= 5; i++) {
multiples.push(num * i);
}
return multiples;
}
console.log(countBy(5)); // [5, 10, 15, 20, 25];
console.log(countBy(10)); // [10, 20, 30, 40, 50];
console.log(countBy(1)); // [1, 2, 3, 4, 5];
console.log(countBy(4)); // [4, 8, 12, 16, 20];
function appendPlusOrMinus(grade) {
const remainder = grade % 10;
if (remainder >= 8) {
return '+';
}
if (remainder <= 1) {
return '-';
}
return '';
}
console.log(appendPlusOrMinus(89)); // right most digit is 9; returns: '+'
console.log(appendPlusOrMinus(91)); // right most digit is 1; returns: '-'
console.log(appendPlusOrMinus(77)); // right most digit is 7; returns: ''
// favoriteFruit = 'orange';
//input: Array<number>
//output: Array<number> with of 2 containing the input array's larget two numbers
function twoLargest(numbers) {
const sortedArray = numbers.sort((a, b) => b - a);
return [sortedArray[0], sortedArray[1]];
}
console.log(twoLargest([1, 5, 9, 7, 10, 2])); // [9, 10];
console.log(twoLargest([2, 4, 11, 3, 1, 20])); // [11, 20];
console.log(twoLargest([30, 1, 4, 2, 30, 0])); // [30, 30];
console.log(twoLargest([6, 5, 5])); // [5, 6];
console.log(twoLargest([1,2])); // [1, 2];)
function whoWillBeAtLeast30(people) {
const endOfYear = new Date('December 31, 2018');
const thirtyYears = (86400000 * 365) * 30;
const peopleWhoWillBeAtLeast30 = []
for (let person of people) {
const { birthday: {month, day, year}, name} = person
const birthday = new Date(`${month} ${day}, ${year}`);
if( (endOfYear - birthday) >= thirtyYears ) {
peopleWhoWillBeAtLeast30.push(name);
}
}
return peopleWhoWillBeAtLeast30;
}
var people = [
{name : 'Sarah', birthday : { month : 'June', day : 10, year : 1980}},
{name : 'Alex', birthday : { month : 'August', day : 21, year : 1984}},
{name : 'Chris', birthday : { month : 'December', day : 20, year : 1983}},
{name : 'Kira', birthday : { month : 'October', day : 30, year : 1988}},
{name : 'Ana', birthday : { month : 'Jan', day : 11, year : 1990}}
];
console.log(whoWillBeAtLeast30(people))