Created
January 12, 2023 02:47
-
-
Save neos1803/00c94aac5abbd35a4c076d271cb89d0e to your computer and use it in GitHub Desktop.
Simple Function to Transform Array of String to Text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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