{"size": 530, "ext": "js", "max_stars_repo_path": "wordwrap/index.js", "max_stars_repo_name": "vargamateistvan/coding-dojo", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wordwrap/index.js", "max_issues_repo_name": "vargamateistvan/coding-dojo", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wordwrap/index.js", "max_forks_repo_name": "vargamateistvan/coding-dojo", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.0833333333, "max_line_length": 64, "alphanum_fraction": 0.6037735849}
const wordwrap = (string, columnNumber) => {
  const NEW_LINE_CHAR = "\n";
  const SPACE_CHAR = " ";

  if (string.length < columnNumber) {
    return string;
  }

  const words = string.split(" ");
  let charNum = 0;
  words.forEach((word, index, array) => {
    charNum += word.length;
    if (charNum > columnNumber) {
      array[index - 1] = array[index - 1].concat(NEW_LINE_CHAR);
      charNum = 0;
    }
    // array[index] = array[index].concat(SPACE_CHAR);
  });

  return words.join("");
};

module.exports = wordwrap;
