Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit e311f1b

Browse files
committed
added more randomness in headertyper
1 parent a66d310 commit e311f1b

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

src/_pages/LandingPage/components/HeaderView/index.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,23 @@ import GithubButton from '../../../../components/buttons/GithubButton';
77
import styles from './styles.module.css';
88
import { useWindowSize } from '../../../../hooks/useWindowSize';
99
import MouseScroller from './components/MouseScroller';
10-
import { animated, useSpring } from 'react-spring';
1110
import Astronaut from './components/Astronaut';
11+
import { shuffle } from '../../../../utils';
1212

1313
const HeaderView: React.FC = () => {
1414
const { siteConfig } = useDocusaurusContext();
1515
const { windowHeight } = useWindowSize();
16-
const [toTypeWords] = useState([
17-
'simple',
18-
'straightforward',
19-
'fast',
20-
'understandable',
21-
'boilerplate free',
22-
'spacy',
23-
'fun',
24-
]);
16+
const [toTypeWords] = useState(
17+
shuffle([
18+
'simple',
19+
'straightforward',
20+
'fast',
21+
'understandable',
22+
'boilerplate free',
23+
'spacy',
24+
'fun',
25+
])
26+
);
2527

2628
return (
2729
<div className={styles.Container}>

src/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export function shuffle<X extends Array<any>>(array: X) {
2+
let currentIndex = array.length;
3+
let temporaryValue = null;
4+
let randomIndex = 0;
5+
6+
// While there remain elements to shuffle...
7+
while (0 !== currentIndex) {
8+
// Pick a remaining element...
9+
randomIndex = Math.floor(Math.random() * currentIndex);
10+
currentIndex -= 1;
11+
12+
// And swap it with the current element.
13+
temporaryValue = array[currentIndex];
14+
array[currentIndex] = array[randomIndex];
15+
array[randomIndex] = temporaryValue;
16+
}
17+
18+
return array;
19+
}

0 commit comments

Comments
 (0)