/**
* Formats a record using fixed-width fields.
*
* Name : left-aligned, width 15
* Age : right-aligned, width 10
* Salary : right-aligned, width 12, 2 decimal places
*/
function formatRecord(
name: string,
age: number,
salary: number
): string {
const nameField: string = name.padEnd(15, ' ');
const ageField: string = age.toString().padStart(10, ' ');
const salaryField: string = salary.toFixed(2).padStart(12, ' ');
return nameField + ageField + salaryField;
}
// Store the formatted string in a variable
const result: string = formatRecord("Pandora", 58, 155000);
console.log(result);
/*
run:
Pandora 58 155000.00
*/