Typescript/러닝 타입스크립트 연습문제

(5장) Secret Secrets - 1.Incoming Cipher

띵킹 2023. 4. 13. 23:48

 

https://github.com/LearningTypeScript/projects/tree/main//projects/functions/secret-secrets/01-incoming-cipher

 

GitHub - LearningTypeScript/projects: Hands-on real world projects that will help you exercise your knowledge of TypeScript.

Hands-on real world projects that will help you exercise your knowledge of TypeScript. - GitHub - LearningTypeScript/projects: Hands-on real world projects that will help you exercise your knowledg...

github.com

좋아요.
당신은 임무를 받아들이기로 선택했습니다.

첫 번째 작업은 텍스트 인코더를 만드는 데 사용할 수 있는 기능을 구현하는 것입니다.
Spy 101 교육에서 기억하시겠지만, 우리는 종종 [ROT13](https://en.wikipedia.org/wiki/ROT13) 과 같은 기능을 사용하여 구경꾼들로부터 문자를 숨깁니다.

당신의 임무는 createCipher 기능을 개발하는 것입니다.
유일한 매개 변수는 문자열을 가져오고 문자열을 반환하는 "cipher" 함수여야 합니다.
반환 형식은 문자열을 사용하여 문자열의 각 문자에 대해 암호를 호출한 결과를 반환하는 함수여야 합니다.

> 팁: "for...of"를 통해 문자열에 반복적으로 접근할 수 있습니다

## 명세

매개 변수:

1. "cipher" : 문자열을 입력하고 다른 문자열을 반환하는 함수

반환: 다음과 같은 함수:
- 매개 변수:
1. '텍스트': 임의의 문자열
- 반환 유형: text의 모든 문자에 cipher를 호출하여 생성된 문자열

## 파일

- "index.ts": "createCipher" 함수를 여기에 적습니다
- "index.test.ts": 'createCipher'를 확인하는 테스트
- "solution.ts": 솔루션 코드
// Write your createCipher function here! ✨
// You'll need to export it so the tests can run it.
type cipher = (string: string) => string 

export const createCipher = (cipher:cipher) => {
    return (text:string) => {
        let newText = '';
        for (const token of text) {
            newText += cipher(token)
        }
        return newText
    }
}

암호화 함수를 매개변수로 받아서,

문자열을 매개변수로 받고, 받아온 암호화 함수를 적용시켜 새 문자열을 반환하는 함수를 반환하는, 

함수를 만드는 문제.

728x90