Juni_Dev_log

(210123_TIL) 'Hello World', 'Two Fer' 본문

CodingTest/Exercism

(210123_TIL) 'Hello World', 'Two Fer'

Juni_K 2021. 1. 23. 21:28

자료구조, 알고리즘 문제를 하루에 1-2개씩 풀기 위해서, 

 

exercism.io/

 

Exercism

Code Practice and Mentorship for Everyone. Level up your programming skills with 1,879 exercises across 38 languages, and insightful discussion with our dedicated team of welcoming mentors. Exercism is 100% free forever.

exercism.io

Exercism 이라는 문제은행 사이트에서 Javascript 언어로 문제 풀이를 진행했다.

 

처음에는 조금 쉬운 난이도인 easy 난이도의 문제 2개를 풀었다.

 

▶ Hello World

Hello World

(Problem)

The classical introductory exercise. Just say "Hello, World!".

"Hello, World!" is the traditional first program for beginning programming in a new language or environment.

The objectives are simple:

  • Write a function that returns the string "Hello, World!".
  • Run the test suite and make sure that it succeeds.
  • Submit your solution and check it at the website.

If everything goes well, you will be ready to fetch your first real exercise.

 

- 함수의 결과로 "Hello, World" 가 나오게 만드는 함수를 작성하라는 문제이다.

 

(Solution)

1
2
3
4
5
6
7
8
9
//
// This is only a SKELETON file for the 'Hello World' exercise. It's been provided as a
// convenience to get you started writing code faster.
//
 
export const hello = () => {
    return 'Hello, World!';   
};
 
cs

화살표 함수로 작성해서 진행했다.

해당 코드는, 

1
2
3
4
5
6
7
8
//
// This is only a SKELETON file for the 'Hello World' exercise. It's been provided as a
// convenience to get you started writing code faster.
//
 
function hello(){
    return 'Hello, World!';
}
cs

와 똑같은 코드이다.

 

ko.javascript.info/arrow-functions-basics

 

화살표 함수 기본

 

ko.javascript.info

 

▶ Two-Fer

(Problem)

Two-fer or 2-fer is short for two for one. One for you and one for me.

Given a name, return a string with the message:

One for name, one for me.

Where "name" is the given name.

However, if the name is missing, return the string:

One for you, one for me.

Here are some examples:

NameString to return

name expression
Alice One for Alice, one for me.
Bob One for Bob, one for me.
You One for you, one for me.
Zaphod One for Zaphod, one for me.

- 이름이 없다면, "One for name, one for me." 를 반환한다.

- 이름이 있다면, name 자리에 해당 이름이 들어가는 문자열을 반환하도록 작성한다.

 

(Solution)

1
2
3
4
5
6
7
8
9
//
// This is only a SKELETON file for the 'Two fer' exercise. It's been provided as a
// convenience to get you started writing code faster.
//
 
export const twoFer = (name="you"=> {
    return `One for ${name}, one for me.`;
};
 
cs

- One for name, one for me. 를 고정적으로 나오도록 하고, name으로 들어가는 값이 삽입되도록 {} 문자열 리터럴을 활용했다.

 

1
2
3
4
5
6
7
8
//
// This is only a SKELETON file for the 'Two fer' exercise. It's been provided as a
// convenience to get you started writing code faster.
//
 
function twoFer(name="you"){
    return `One for ${name}, one for me.`;
}
cs

 

'CodingTest > Exercism' 카테고리의 다른 글

(200128_TIL) 'Bank Account'  (0) 2021.01.28
(200127_TIL) 'Pangram'  (0) 2021.01.27
(200126_TIL) 'Space Age'  (0) 2021.01.26
(200125_TIL) 'Gigasecond', 'RNA Transcription'  (0) 2021.01.25
(200124_TIL) 'Resistor Color', 'Resistor Color Duo'  (0) 2021.01.24
Comments