You are viewing a single comment's thread. Return to all comments →
My code fails all three tests, but I can carry out the tests manually and it works just fine. Maybe I broke it with my suboptimal solution :D
import React, { useState } from "react"; const OMITTED_WORDS = ["a", "the", "and", "or", "but"]; function WordOmitter() { const [inputText, setInputText] = useState(""); const [omitWords, setOmitWords] = useState(true); const handleInputChange = (e) => { setInputText(e.target.value); }; const toggleOmitWords = () => { setOmitWords(!omitWords); }; const clearFields = () => { setInputText('') }; const getProcessedText = () => { if (!omitWords) return inputText let wordArray = inputText.split(' '); let newArray = wordArray.reduce((acc, word) => { if (!OMITTED_WORDS.includes(word.toLowerCase())) { acc.push(word + ' '); } return acc },[]) return newArray; }; return ( <div className="omitter-wrapper"> <textarea placeholder="Type here..." value={inputText} onChange={handleInputChange} data-testid="input-area" /> <div> <button onClick={toggleOmitWords} data-testid="action-btn"> {omitWords ? "Show All Words" : "Omit Words"} </button> <button onClick={clearFields} data-testid="clear-btn"> Clear </button> </div> <div> <h2>Output:</h2> <p data-testid="output-text">{getProcessedText()}</p> </div> </div> ); } export { WordOmitter };
Seems like cookies are disabled on this browser, please enable them to open this website
Word Omitter
You are viewing a single comment's thread. Return to all comments →
My code fails all three tests, but I can carry out the tests manually and it works just fine. Maybe I broke it with my suboptimal solution :D