-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask45.ts
24 lines (21 loc) · 1005 Bytes
/
task45.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//Cars: Write a function that stores information about a car in a Object. The function should always receive a manufacturer and a model name. It should then accept an arbitrary number of keyword arguments. Call the function with the required information and two other name-value pairs, such as a color or an optional feature. Print the Object that’s returned to make sure all the information was stored correctly.
interface Car {
manufacturer: string;
modelName: string;
[key: string]: any;
}
function createCar(manufacturer: string, modelName: string, ...options: any[]): Car {
const car: Car = {
manufacturer,
modelName,
};
for (let i = 0; i < options.length; i += 2) {
const key = options[i];
const value = options[i + 1];
car[key] = value;
}
console.log(car)
return car;
}
createCar('Toyota', 'XLI', 'color', 'black', 'optionalFeature', 'sunroof');
createCar('Toyota', 'GLI', 'color', 'gray', 'optionalFeature', 'abs');