Created
April 18, 2022 11:52
-
-
Save emmsdan/50ad7c4ae5affd767923ea1aaed56d0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create array | |
const array = [] | |
// get the user word | |
const word = 'lol' | |
array.push(word) | |
// check if it's palindrom | |
function isPal(word) { | |
return word.split('').reverse().join('') === word; | |
} | |
// instead of consolo.log store the result and the word | |
if (isPal(word)) { | |
console.log('is pal'); | |
array.push({word, result: 'is pal'}) | |
} else { | |
array.push({word, result: 'is not pal'}) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const App = () => { | |
const [word, setWord] = React.useState(''); | |
const [array, setArray] = React.useState([]); | |
function isPal(word) { | |
return word.split('').reverse().join('') === word; | |
} | |
function setValue (evnt) { | |
setWord(evnt.target.value) | |
} | |
const btnClick = () => { | |
setArray([...array, word]); | |
setArray((arr) => [...arr, word]); | |
} | |
return <> { array.map(w => <div>{w}</div>)} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment