• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please help me with this Functional Mapping

 
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have problem in getting the solution for this question :


Given a list of strings, return a list where each string has "y" added at its start and end.

moreY(["a", "b", "c"]) → ["yay", "yby", "ycy"]
moreY(["hello", "there"]) → ["yhelloy", "ytherey"]
moreY(["yay"]) → ["yyayy"]



And here's my attempt so far :



I am stuck as I can't define a Sting first and then using index of before using sub string...

Am not I trying hard enough ?

Hope someone can give me some hints...

Tks.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:. . . Am not I trying hard enough ? . . .

No, you are trying too hard. You are concatenating the wrong thing, but your use of the + operator would work as long as you add the right thing.
 
Bartender
Posts: 390
47
Firefox Browser MySQL Database Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a question to maybe help you see what you are doing more clearly: what does startsWith() do, and what does it return? Then, why have you chosen to use it?
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

tangara goh wrote:. . . Am not I trying hard enough ? . . .

No, you are trying too hard. You are concatenating the wrong thing, but your use of the + operator would work as long as you add the right thing.




I tried something very straight forward but why am I getting double yy at the front and end of a, b and c ?


[yyayy, yybyy, yycyy]


 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You call moreY() two times: first on line 15 then a second time on line 16 so naturally, you'll get two "y"s
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic