forked from thesam73/wordle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshare.ts
More file actions
31 lines (29 loc) · 815 Bytes
/
share.ts
File metadata and controls
31 lines (29 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { getGuessStatuses } from './statuses'
import { solutionIndex } from './words'
import { GAME_TITLE } from '../constants/strings'
export const shareStatus = (guesses: string[], lost: boolean) => {
navigator.clipboard.writeText(
`${GAME_TITLE} ${solutionIndex} ${lost ? 'X' : guesses.length}/6\n\n` +
generateEmojiGrid(guesses)
)
}
export const generateEmojiGrid = (guesses: string[]) => {
return guesses
.map((guess) => {
const status = getGuessStatuses(guess)
return guess
.split('')
.map((_, i) => {
switch (status[i]) {
case 'correct':
return '🟩'
case 'present':
return '🟨'
default:
return '⬜'
}
})
.join('')
})
.join('\n')
}