Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

discord.js Function to replace certain characters with a pattern

//This was created for my text based Discord game: Hangman
//This function will check the occurences of a certain letter in a word and return a formatted version
//Ex: word (not shown is mother), but is shown as - - - - - - (in bold with starting and ending **)
//User enters e
//This function then returns: - - - - e - (also in bold with **)

function display(text, chars = [], format = char => `**${char === null ? "-" : char}**`, separator = " ") {
    const items = [];
    text.trim().split("").forEach(char => {
        items.push(format(chars.indexOf(char) == -1 ? null : char));
    });
    return items.join(separator);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: react extends component with style 
Javascript :: how to uitree clone in jquery 
Javascript :: removes all item occurrences in array 
Javascript :: Combine multiple JSONs Into One 
Javascript :: Class Has a Constructor Function 
Javascript :: store in memory an array (two-dimensional) 10rows x 10columns with random integers and show the number of elements between 10 and 20 javvascript 
Javascript :: Return object in parenthesis to avoid it being considered a wrapping function body 
Javascript :: jqxAngular 
Javascript :: Backbone Model Set Can Set Muliple Values At Once 
Javascript :: use stigviewr 
Javascript :: Backbone Initialize vs Render 
Javascript :: how to read json data from database in laravel 
Javascript :: Shopify cart context 
Javascript :: TOP Array Methods 
Javascript :: erc721 abi json 
Javascript :: passing third parameter in context.commit vuejs 
Javascript :: HSET redis, HINCRBYFLOAT redis 
Javascript :: modalInstance.result.then when execute 
Javascript :: linux Error HH604: Error running JSON-RPC server 
Javascript :: upload file to api angular 
Javascript :: array reverse 
Javascript :: router.put method 
Javascript :: suscribe messagechannel lwc 
Javascript :: on page navigate event javascript 
Javascript :: Hexo - Execute Console Commands 
Javascript :: how to put condition on pagination material table 
Javascript :: for (i = 0; i < N; i++) for (j = 0; j < N; j++) { .... some O(1) code ... } 
Javascript :: javascript How can i do optional function 
Javascript :: angular create spec file for existing component 
Javascript :: Issue in applying margin using angular "data-ng-style" 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =