First Kumite don't really know what I'm supposed to be doing but I refactored this code a bit.
Shouldn't use arrow functions except for delegates imo. You don't need calling context for this function so no need for it.
Just iterate backwards over the array instead of doing unecessary subtractiosn.
function invert(str) { let rev_str = ""; for (let i = str.length-1; i >=0 ; i--) { rev_str += str[i]; } return rev_str; }
const invert = str => {- function invert(str) {
- let rev_str = "";
for (let i = 0; i < str.length; i++) {rev_str += str[str.length - 1 - i];- for (let i = str.length-1; i >=0 ; i--) {
- rev_str += str[i];
- }
- return rev_str;