Skip to content

ideas #2

@Uzlopak

Description

@Uzlopak

I think there is still some performance to gain.

e.g. currently you have to create a variable lastIndex.

Some ideas.

const empty = "";
function join(output, separator = ",") {
  const length = output.length
  if (length === 0) {
    return empty;
  }

  let str = empty;
  let i = 1
  while (i < length) {
    // It is faster not to use a template string here
    str += separator;
    str += output[i++];
  }
  return output[0] + str
}
function join(array, separator) {
  const length = array.length
  if (length === 0) {
    return "";
  } else if (length === 1) {
    return array[0];
  } else {
    let str = "";
    let i = 1;
    while (i < length) {
      // It is faster not to use a template string here
      str += separator;
      str += array[i++];
    }
    return array[0] + str;
  }
}

Or something with a switch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions