For this week's assignment, I wanted to create a word replacer that would replace all cat/cats with dog/dogs. \DOGS/

I modified FleschIndex's p5.js example to have the program loop each word to see if it contains cat and then change it to dog.

Here’s what serves as the main function in the code:

// Process the text to replace 'cat' with 'dog'
function process(text) {
  let words = text.split(/\\b/); // Split the text by word boundaries
  for (let i = 0; i < words.length; i++) {
    if (words[i].toLowerCase().includes('cat')) {
      words[i] = words[i].replace(/cat/gi, 'dog');
    }
  }
  return words.join('');
}

/\\b/ helps in precisely locating and replacing substrings that contain "cat" without accidentally merging parts of different words or punctuation (this professional explanation comes from GPT). Then I look for the correct combination in the inputs, which is then replaced with dog. /gi makes sure that the program searches globally & case insensitively.

https://editor.p5js.org/Joycie/sketches/sX67pTqWn

I have a question about the first exercise - I had a lot of fun with randexp.js, but I noticed that in the example, . +/ will create

image.png

This includes ...... Some random Chinese/Korean/non-recognizable characters. But in my input field, they are just English/numbers/punctuation marks. Is there any rule to set it this way, or is it because the content of the input field can't be converted ......?

https://developers.google.com/maps

https://docs.sahha.ai/