Skip to content

Instantly share code, notes, and snippets.

@emmsdan
Created April 18, 2022 11:52
Show Gist options
  • Save emmsdan/50ad7c4ae5affd767923ea1aaed56d0c to your computer and use it in GitHub Desktop.
Save emmsdan/50ad7c4ae5affd767923ea1aaed56d0c to your computer and use it in GitHub Desktop.
// 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'})
}
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