-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Word Count #244
Comments
@mickrig thanks, can you post the code as text here in the issue? https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks |
@larshp Yes, sure, please find the code below CLASS zcl_word_count DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
TYPES:
BEGIN OF return_structure,
word TYPE string,
count TYPE i,
END OF return_structure,
return_table TYPE STANDARD TABLE OF return_structure WITH KEY word.
METHODS count_words
IMPORTING
!phrase TYPE string
RETURNING
VALUE(result) TYPE return_table .
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_word_count IMPLEMENTATION.
METHOD count_words.
DATA(string) = replace( val = to_lower( phrase ) sub = `'` with = `` occ = 0 ).
string = replace( val = string sub = `\t` with = ` ` occ = 0 ).
string = replace( val = string sub = `\n` with = ` ` occ = 0 ).
string = condense( replace( val = string regex = `[^a-z0-9]` with = ` ` occ = 0 ) ).
DO.
TRY.
DATA(substring) = segment( val = string
index = sy-index
sep = ` ` ).
TRY.
DATA(single_count) = REF #( result[ word = substring ]-count ).
single_count->* += 1.
CATCH cx_sy_itab_line_not_found.
APPEND VALUE #( word = substring count = 1 ) TO result.
ENDTRY.
CATCH cx_sy_strg_par_val.
EXIT.
ENDTRY.
ENDDO.
ENDMETHOD.
ENDCLASS. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi guys,
I have an issue with exercise word count. It works in ABAP but not on Exercism.
It looks like that the plattform is not able to work with adding 1 to the reference which is marked red.
All tests with a word count greater than 1 fail.
Please have a look on the screenshot.
Thanks in advance.
Michael
The text was updated successfully, but these errors were encountered: