<commit_before>import {ISolution} from '../solution.interface';

export class Solution implements ISolution<string, string> {
  static PRONOUNS: string[] = [
    "I", "YOU", "HE", "SHE", "IT", "WE", "THEY"
  ];

  static INVALID: string = "Too difficult, this sentence is.";

  solve(input: string) {
    var parts = input.split(' ');
    if (!Solution.EqualsAnyPronoun(parts[0])) {
      return Solution.INVALID;
    }

    var rearranged = Solution.RearrangeParts(parts);

    rearranged = Solution.FinishWithFullStopIfNeeded(rearranged);

    var end = rearranged.join(" ");

    return end;
  }

  static EqualsAnyPronoun(input: string): boolean {
    for (var p of Solution.PRONOUNS) {
      if (p === input.toUpperCase()) {
        return true;
      }
    }

    return false;
  }

  static RearrangeParts(input: string[]): string[] {
    var parts = [];
    for (var i = 2; i < input.length; i++) {
      parts.push(input[i]);
    }

    parts = Solution.AddCommaToLastPart(parts);

    parts.push(input[0]);
    parts.push(input[1]);

    return parts;
  }

  static AddCommaToLastPart(input: string[]): string[] {
    var pointer = input.length - 1;

    input[pointer] = input[pointer] + ',';

    return input;
  }

  static FinishWithFullStopIfNeeded(input: string[]): string[] {
    var pointer = input.length - 1;
    var value = input[pointer];
    var valuePointer = value.length - 1;

    if (value[valuePointer] === '.') {
      return input;
    }

    value = value + '.';

    input[pointer] = value;
    return input;
  }
}<commit_msg>Remove ending symbols<commit_after>import {ISolution} from '../solution.interface';

export class Solution implements ISolution<string, string> {
  static PRONOUNS: string[] = [
    "I", "YOU", "HE", "SHE", "IT", "WE", "THEY"
  ];

  static INVALID: string = "Too difficult, this sentence is.";

  solve(input: string) {
    var parts = input.split(' ');
    if (!Solution.EqualsAnyPronoun(parts[0])) {
      return Solution.INVALID;
    }

    var rearranged = Solution.RearrangeParts(parts);

    rearranged = Solution.FinishWithFullStopIfNeeded(rearranged);

    var end = rearranged.join(" ");

    return Solution.CapitaliseString(end);
  }

  static EqualsAnyPronoun(input: string): boolean {
    for (var p of Solution.PRONOUNS) {
      if (p === input.toUpperCase()) {
        return true;
      }
    }

    return false;
  }

  static RemoveEndingSymbols(input: string[]): string[] {
    var lastPart = input[input.length - 1];

    var lastCharacter = lastPart[lastPart.length - 1];
    if (lastCharacter === ',' || lastCharacter === '.' || lastCharacter === '!') {
      input[input.length - 1] = lastPart.substr(0, lastPart.length - 1);
    }

    return input;
  }

  static RearrangeParts(input: string[]): string[] {
    input = Solution.RemoveEndingSymbols(input);

    var parts = [];
    for (var i = 2; i < input.length; i++) {
      parts.push(input[i]);
    }

    parts = Solution.AddCommaToLastPart(parts);

    parts.push(input[0]);
    parts.push(input[1]);

    return parts;
  }

  static AddCommaToLastPart(input: string[]): string[] {
    var pointer = input.length - 1;

    input[pointer] = input[pointer] + ',';

    return input;
  }

  static FinishWithFullStopIfNeeded(input: string[]): string[] {
    var pointer = input.length - 1;
    var value = input[pointer];
    var valuePointer = value.length - 1;

    if (value[valuePointer] === '.') {
      return input;
    }

    value = value + '.';

    input[pointer] = value;
    return input;
  }

  static CapitaliseString(input: string): string {
    input = Solution.ReplaceAt(input, input[0].toUpperCase(), 0);

    return input;
  };

  static ReplaceAt(input: string, replace: string, index: number): string {
    return input.substr(0, index) + replace + input.substr(index + replace.length);
  }
}
{'fraction_non_alphanumeric': 0.15134994807892005, 'fraction_numerical': 0.005711318795430945, 'mean_word_length': 3.030334728033473, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4204923', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1221, 'n_words': 291}