Split

Splits a s​tring​ into an array of strings, without any JavaScript method at all.

3 replies
  1. japanfever
    japanfever says:
    
    //japanfever variant E3839EE383AAE382AAE9B3A9E38388E383ACE383AD
    
    function split1(str, del) {
      let arr = [];
      let piece = "";
      for (let i = 0; i < str.length; i++) {
        let j = 0;
        while (j < del.length && (i + j) < str.length && str[i + j] == del[j]) j++;
        if (j == del.length) {
          arr.push(piece);
          piece = "";
          i += j - 1;
        } else {
          piece += str[i];
        }
      }
      arr.push(piece);
      return arr;
    }
    
    

Comments are closed.