Reverse the order of lines of a text
JavaScript
const reverseLines = (str) => str.split(/\r?\n/).reverse().join('\n')
TypeScript
const reverseLines = (str: string): string => str.split(/\r?\n/).reverse().join('\n')
Examples
reverseLines(`one
two
three`)
/* Output */
/*
three
two
one
*/