What is the smallest way to say this:

What is the most elegant way to say it in JS ?:

search_keyword = search_keyword.toLowerCase();
search_keyword = search_keyword.replace(/[^\w\s]/gi, '');
search_keyword = search_keyword.replace(' and ', '&all=');
search_keyword = search_keyword.replace(' or ', '&any=');
search_keyword = search_keyword.replace(' ', '&all=');
search_keyword = '&all=' + search_keyword;

Many thanks

+3
source share
1 answer

You can simply link them:

search_keyword = '&all=' + search_keyword.toLowerCase()
.replace(/[^\w\s]/gi, '')
.replace(' and ', '&all=')
.replace(' or ', '&any=')
.replace(' ', '&all=');
+3
source

Source: https://habr.com/ru/post/1783874/


All Articles