Get acronym using Lambda

Options

I'm trying to get the acronym of the text variable with a Lambda function

var str = $this;

var matches = str.match(/\b(\w)/g); // ['J','S','O','N']

var acronym = matches.join(''); // JSON

return(acronym)

The function doesn't work with $this.


I've used (return $this;) and I've successfully got a result. This means the variable is available.

Please guide me where I am doing wrong


Answers

  • dorilama
    dorilama Member
    Options

    Is your code all in one line in the editor? If yes then your comment is commenting the rest of the code.

    Quick test: try to remove the comments.

  • George
    Options

    This doesn't help, unfortunately. I'm still getting Cannot read properties of null (reading 'join')

  • George
    Options

    I've got working JS

    var str = $this;

    let acronym = str.split(/\s/).reduce((response,word)=> response+=word.slice(0,1),'')

    return(acronym)