JSFiddle - React, Tailwind, and code Playground

by btipling

JavaScript

function trim(str) {
    var i;
    for (i = 0; /\s/.test(str[i]); i++) {}
    str = str.substr(i);
    for (i = str.length - 1; /\s/.test(str[i]); i--) {}
    return str.substr(0, i);
  }

console.log("\"" + trim("    fooo    ") + "\"");
console.log("\"" + trim("    fooo  asdf  ") + "\"");

console.log("\"" + trim("    fooo  asdf \n doo \t\n ") + "\"");

console.log("\"" + trim(" \n \t   fooo    ") + "\"");