by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • May 14 22:38
    @bjorno43 banned @minitechtips_twitter
  • May 14 22:37
    @bjorno43 banned @real-action
  • Feb 01 00:26
    @bjorno43 banned @Ndoua
  • Jan 07 03:10
    @bjorno43 banned @doctor-sam
  • Aug 17 2019 09:33
    User @bjorno43 unbanned @linkin-park
  • Jun 20 2019 21:19
    @bjorno43 banned @shenerd140
  • May 10 2019 09:13
    @bjorno43 banned @zhaokunhaoa
  • Apr 27 2019 19:46
    @mstellaluna banned @zhonghuacx
  • Apr 25 2019 17:12
    @mstellaluna banned @cmal
  • Apr 01 2019 18:11
    thecodingaviator labeled #31179
  • Apr 01 2019 18:11
    thecodingaviator labeled #31179
  • Apr 01 2019 18:09
    thecodingaviator commented #31179
  • Apr 01 2019 18:09
    thecodingaviator labeled #31182
  • Apr 01 2019 18:09
    thecodingaviator labeled #31182
  • Apr 01 2019 18:07
    thecodingaviator commented #31182
  • Apr 01 2019 18:07
    thecodingaviator labeled #31190
  • Apr 01 2019 18:07
    thecodingaviator labeled #31190
  • Apr 01 2019 18:07
    thecodingaviator commented #31190
  • Apr 01 2019 18:05
    thecodingaviator commented #31157
  • Apr 01 2019 18:04

    thecodingaviator on master

    remove A (#31157) (compare)

urvashi9
@urvashi9
Guys. I need help with Bonfire: Confirm the Ending
CamperBot
@camperbot
type bonfire name to get some info on that bonfire. And check HelpBonfires chatroom
urvashi9
@urvashi9
bonfire confirm the ending
CamperBot
@camperbot

:fire:Bonfire: Confirm the Ending :link:

function end(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  return str;
}

end('Bastian', 'n');

Check if a string (first argument) ends with the given target string (second argument).

more info:  bf details | bf links | hint

urvashi9
@urvashi9
This is my code:
function end(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  var string=str.replace("^[A-Za-z]+","");
  var a=string.substr(-1,1);
  var b=target;
  if(a==b)
    {
      return true;
    }
  else
    {
      return false;
    }
}

end("Bastian", "n", "");
But as you can see, it compares the last letter, instead of the last wode.
Dealga McArdle
@zeffii
@urvashi9 . your equality is checked with == , should it be ?
urvashi9
@urvashi9
word*
This code works fine if I want to confirm that the sentence ends with my target letter.
Manish Gupta
@mformanish
@dting Thanks
CamperBot
@camperbot
mformanish sends brownie points to @dting :sparkles: :thumbsup: :sparkles:
:star: 1185 | @dting | http://www.freecodecamp.com/dting
urvashi9
@urvashi9
But the problem needs us to match the whole target. If it is a letter, It needs to see if that is the last letter of the phrase. And if it is a word, it needs to see if it is infact the last word ofthe phrase.
Dealga McArdle
@zeffii
is this for a bonfire?
urvashi9
@urvashi9
Yes.
Dealga McArdle
@zeffii
link?
urvashi9
@urvashi9
bonfire confirm the ending
CamperBot
@camperbot

:fire:Bonfire: Confirm the Ending :link:

function end(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  return str;
}

end('Bastian', 'n');

Check if a string (first argument) ends with the given target string (second argument).

more info:  bf details | bf links | hint

DTing
@dting
@urvashi9 not last word. just that str ends with target
urvashi9
@urvashi9
yes, but my code only works if the target is a letter
Can anyone tell me how to do it if the target is a word?
I have posted my code above
DTing
@dting
bf links
CamperBot
@camperbot
DTing
@dting
use negative value for substrargument = to target's length
urvashi9
@urvashi9
I did.
DTing
@dting
no
you did substr(-1, 1)
urvashi9
@urvashi9
Oh wait. Just figured it out!!
Thanks to you! @dting
CamperBot
@camperbot
urvashi9 sends brownie points to @dting :sparkles: :thumbsup: :sparkles:
:star: 1186 | @dting | http://www.freecodecamp.com/dting
Dealga McArdle
@zeffii
@urvashi9
function end(str, target) {
  return new RegExp(target+"$").test(str)
}
i learned that today :)
urvashi9
@urvashi9
@dting When you said I needed to use target's length in substr, I was like, "Why didn't I think of that?!" Haha.
@zeffii What does this code do?
DTing
@dting
it includes the explaination of @zeffii code
its at the bottom
urvashi9
@urvashi9
Oh alright. I am going to check it out.
:)
Dealga McArdle
@zeffii
it uses a regular expression.. and asserts that whatever 'target' is , that the 'str' being tested ends with target ( because of the $, to denote end of string)
urvashi9
@urvashi9
Okay, I did not know that. Thanks @zeffii
CamperBot
@camperbot
urvashi9 sends brownie points to @zeffii :sparkles: :thumbsup: :sparkles:
:star: 358 | @zeffii | http://www.freecodecamp.com/zeffii
DTing
@dting
ya that works until your target includes certain characters, for example:
end("asdfadsf", "[a-z]")
// true
Dealga McArdle
@zeffii
@dting, valid point :)
that doesn't mean it's not really useful in controlled circumstances
CamperBot
@camperbot
:trollface: troll problems? notify admins here