mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-19 06:03:50 +01:00
20 lines
499 B
TypeScript
20 lines
499 B
TypeScript
/**
|
|
* Returns the input array as a comma separated string.
|
|
*
|
|
* Does several things that Array.toString() doesn't do
|
|
* - Adds brackets around the array
|
|
* - Adds quotation marks around strings
|
|
*/
|
|
export function arrayToString<T>(a: T[]) {
|
|
const vals: any[] = [];
|
|
for (let i = 0; i < a.length; ++i) {
|
|
let elem: any = a[i];
|
|
if (typeof elem === "string") {
|
|
elem = `"${elem}"`;
|
|
}
|
|
vals.push(elem);
|
|
}
|
|
|
|
return `[${vals.join(", ")}]`;
|
|
}
|