bitburner-src/utils/helpers/arrayToString.ts

20 lines
499 B
TypeScript
Raw Normal View History

2018-07-08 07:11:34 +02:00
/**
* Returns the input array as a comma separated string.
2019-02-09 03:46:30 +01:00
*
* Does several things that Array.toString() doesn't do
* - Adds brackets around the array
* - Adds quotation marks around strings
2018-07-08 07:11:34 +02:00
*/
export function arrayToString<T>(a: T[]) {
2019-02-09 03:46:30 +01:00
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(", ")}]`;
}