GitHub 6248★

Reverse the order of lines of a text

JavaScript version

const reverseLines = (str) => str.split(/\r?\n/).reverse().join('\n');

TypeScript version

const reverseLines = (str: string): string => str.split(/\r?\n/).reverse().join('\n');

Examples

reverseLines(`one
two
three
`
);

/* Output */
/*
three
two
one
*/
Follow me on and to get more useful contents.