4 kyu

Paragraph Setting: Align Left

92 of 98discotechne

Description:

Write a code that takes some text (argument 1) and processes it into a paragraph one line at a time. The lines should break as near as possible to the maximum line length (argument 2), breaking words if needed and inserting a hyphen to indicate where a word has been broken.

Follow these rules:

  • Spaces and punctuation, including inserted hyphens, should be included in line length.
  • There should be no spaces at the start or end of a line. Any such spaces should be removed and so not included in line length.
  • Any punctuation adjoining the start or end of a word should not be detached from the word by a line break.
  • Any added hyphens must be at least two alphanumeric characters from both the start and the end of the word being broken (or from the nearest hyphen, for words that are already hyphenated). If this is not possible, the line should instead be broken either
    1. at the previous white space, or
    2. if the word is already hyphenated and the hyphen lies before the maximum line length, after that hyphen (but not before such hyphens).

For the purpose of this exercise, it can be assumed that:

  • the maximum line length will never be less than 15 characters;
  • any input text will be standard prose throughout, and will not contain any accented characters ( e.g. é );
  • any input text will use spaced en-dashes for parenthesis, rather than non-spaced em-dashes (see http://www.dashhyphen.com/en-dash/);
  • there will be no long stretches of non-alphanumeric characters in the input text (although quotation marks, including for nested quotations, should be accounted for), and no multiple spaces; " and "'" serve as quotation marks.
  • underscores are included in alphanumeric characters.
Algorithms

Similar Kata:

Stats:

CreatedJun 11, 2017
PublishedJun 11, 2017
Warriors Trained611
Total Skips8
Total Code Submissions1571
Total Times Completed98
JavaScript Completions92
Python Completions9
Total Stars17
% of votes with a positive feedback rating85% of 20
Total "Very Satisfied" Votes16
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes2
Total Rank Assessments3
Average Assessed Rank
4 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
5 kyu
Ad
Contributors
  • discotechne Avatar
  • JohanWiltink Avatar
  • pbldmngz Avatar
  • dfhwze Avatar
Ad