dimanche 3 janvier 2021

JavaScript( username with the '@' symbol) [closed]

I was traing to make this exercise, I don't know how.

My elves are having trouble keeping track of all the naughty and nice people on social media. I'm told you coder types can make their lives easier!

Can you help them identify the recipients in social media posts?

Recipients are identified by preceding their username with the '@' symbol Usernames can contain letters, numbers, underscores and hyphens Any character which is not a valid username character will separate the recipients from the rest of the message

If we pass your code the message and a number, can you return the username it represents?

My elves tell me they want something like this:

var message = "@Santa I've been good this year, can I get a PS5 like @Userxyz?";
GetRecipient(message,1)="Santa";
GetRecipient(message, 2)="Userxyz";
GetRecipient(message, 3)="";

Remember there may be other @ symbols floating around in all the messages, for all sorts of reasons!

I'll make sure you go on the good list for this one.

   getRecipient = function(message, position) {
};

require('./Solution.js');

describe("SolutionTests", function() {

    
    it("Test1", function() {
        expect(getRecipient("@JoeBloggs yo", 1)).toEqual("JoeBloggs");
    });

    it("Test2", function() {
        expect(getRecipient("Hey @Joe_Bloggs what time are we meeting @FredBloggs?", 2)).toEqual("FredBloggs");
    });

});

Aucun commentaire:

Enregistrer un commentaire