Skip to content

Instantly share code, notes, and snippets.

@neos1803
Created January 12, 2023 02:47
Show Gist options
  • Save neos1803/00c94aac5abbd35a4c076d271cb89d0e to your computer and use it in GitHub Desktop.
Save neos1803/00c94aac5abbd35a4c076d271cb89d0e to your computer and use it in GitHub Desktop.
Simple Function to Transform Array of String to Text
/**
* Input: ['First Message', 'Second Message']
* Output: `1. First message \n 2. Second Message \n`
*/
export function arrayToTextWithEnter(arr: Array<any>): String {
let response = ``
arr.forEach((v, i) => {
response = response + `${i + 1}. ${v} \n`
});
return response;
}
/**
* Input: ['First Message', 'Second Message']
* Output: `(First Message, Second Message)`
*/
export function arrayToText(arr: Array<any>): String {
let response = `(`
if (arr.length === 0) return "";
arr.forEach((v, i) => {
response = response + v + (i !== arr.length - 1 ? ", " : ")")
});
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment