The document contains three code snippets that provide solutions to different problems: 1) A function that checks if a word can be found on a game board. 2) A function that returns the most frequent days of the week for a given year. 3) A function that replaces instances of 'you' or similar words with 'your client' in a given string.
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
13 views
Challenge
The document contains three code snippets that provide solutions to different problems: 1) A function that checks if a word can be found on a game board. 2) A function that returns the most frequent days of the week for a given year. 3) A function that replaces instances of 'you' or similar words with 'your client' in a given string.
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2
challenge
NO.3
const autocorrect = input => {
//let a='You u youville utube you youyouyou uuu raiyou united youuuu u you'; console.log(input); console.log('||'); let regex=/(\byou\b|\byou+u\b|\bu\b)/gi console.log(input.replace(regex, "your client"));
return input.replace(regex, "your client");
};
NO.2
const mostFrequentDays = year => {
let dayName = function (d){ return d.toLocaleString('en',{weekday:'long'}) }; // 1 Jan let d = new Date(year, 0, 1); let d0 = dayName(d); // 31 Dec let d1 = dayName(new Date(year, 11, 31)); let result = d0 == d1? [d0] : [d0, d1]; // If d0 is Sunday, reverse result return d.getDay()? result : result.reverse(); };