• Post Reply Bookmark Topic Watch Topic
  • New Topic

my code is too long - refactor this simple code - string comparing  RSS feed

 
Greenhorn
Posts: 23
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actual question:
Given two strings, return true if either of the strings appears at the very end of the other string, ignoring upper/lower case differences (in other words, the computation should not be "case sensitive"). Note: str.toLowerCase() returns the lowercase version of a string.

endOther("Hiabc", "abc") → true
endOther("AbC", "HiaBc") → true
endOther("abc", "abXabc") → true

my solution:




===============================================
i m 90% sure this code can be simplified, but i don't know other logic or way of thinking about this simple exercise

can someone help me refactor it and make it smaller?
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you look at the API for the String object? There is probably already a method that helps you see if a String endsWith another String...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!