Skip to content

Commit 5813a52

Browse files
committed
Feat : generate random nickname 함수 구현
- json 파일에 형용사 명사 따로 두고 거기서 하나씩 뽑아오게 수정
1 parent 62a36e0 commit 5813a52

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/backend/utils/generateRandom.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
import nickname from './nickname.json';
2+
13
const randomStrings = new Set();
24

35
const generateRandomString = () =>
46
Math.random().toString(36).substr(2, 5).toUpperCase();
57

68
export default {
7-
nickname: () => '코딩하는 덕싯',
9+
nickname: () => {
10+
const { adjective: adj, noun } = nickname;
11+
const randomAdj = adj[Math.floor(Math.random() * adj.length)];
12+
const randomNoun = noun[Math.floor(Math.random() * noun.length)];
13+
return `${randomAdj} ${randomNoun}`;
14+
},
815
color: () => '#222222',
916
code: () => {
1017
let randomString = generateRandomString();

src/backend/utils/nickname.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"adjective": ["코딩하는", "열정적인", "JS덕후", "얼죽아", "카페인중독", "패션왕", "집에만 있는", "밤새는", "배고픈", "고독한", "발명왕", "청소를 좋아하는", "명탐정"],
3+
"noun": ["덕싯", "캠퍼", "뽀로로", "도라에몽", "개발자", "코딩왕", "미식가", "산타클로스", "집사", "프론트 개발자", "백엔드 개발자", "iOS 개발자", "코난", "아티스트"]
4+
}

0 commit comments

Comments
 (0)