Skip to main content
edited tags; edited title
Link
Legato
  • 9.9k
  • 4
  • 50
  • 118

String 'expanding' code challenge - reinserting repeating characters

Tweeted twitter.com/#!/StackCodeReview/status/549557619430801409
deleted 2 characters in body
Source Link
Legato
  • 9.9k
  • 4
  • 50
  • 118

UpdateNote: So this isn't incorrectly perceived as a 'do this for me' question, as stated in edit 2, I've already accounted for all cases.

Update: So this isn't incorrectly perceived as a 'do this for me' question, as stated in edit 2, I've already accounted for all cases.

Note: So this isn't incorrectly perceived as a 'do this for me' question, as stated in edit 2, I've already accounted for all cases.

Rolledback changed code
Source Link
Heslacher
  • 51k
  • 5
  • 83
  • 177

Update: So this isn't incorrectly perceived as a 'do this for me' question, as stated in edit 2, I've already accounted for all cases. I got rid of isNumeric(recognition to rofl's answer) lengthen is the same, but blowup is now this:

    public static String blowup(String str) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            if (!Character.isDigit(str.charAt(i))) {
                sb.append(str.charAt(i));
            }
            else if (i == str.length() - 1) { return sb.toString(); }
            else {
                sb.append(lengthen(str.charAt(i + 1),
                    Character.getNumericValue(str.charAt(i))));
            }
        }
        return sb.toString();
    }

Update: So this isn't incorrectly perceived as a 'do this for me' question, as stated in edit 2, I've already accounted for all cases. I got rid of isNumeric(recognition to rofl's answer) lengthen is the same, but blowup is now this:

    public static String blowup(String str) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            if (!Character.isDigit(str.charAt(i))) {
                sb.append(str.charAt(i));
            }
            else if (i == str.length() - 1) { return sb.toString(); }
            else {
                sb.append(lengthen(str.charAt(i + 1),
                    Character.getNumericValue(str.charAt(i))));
            }
        }
        return sb.toString();
    }

Update: So this isn't incorrectly perceived as a 'do this for me' question, as stated in edit 2, I've already accounted for all cases.

Less wordy
Source Link
Legato
  • 9.9k
  • 4
  • 50
  • 118
Loading
Relevant code update
Source Link
Legato
  • 9.9k
  • 4
  • 50
  • 118
Loading
Added some helpful test cases
Source Link
Legato
  • 9.9k
  • 4
  • 50
  • 118
Loading
added 251 characters in body
Source Link
Legato
  • 9.9k
  • 4
  • 50
  • 118
Loading
added 186 characters in body
Source Link
Legato
  • 9.9k
  • 4
  • 50
  • 118
Loading
title, some formatting
Source Link
rolfl
  • 98.1k
  • 17
  • 220
  • 419
Loading
Source Link
Legato
  • 9.9k
  • 4
  • 50
  • 118
Loading