Create a function with two arguments that will return an array of the first n multiples of x.
Assume both the given number and the number of times to count will be positive numbers greater than 0.
Return the results as an array or list ( depending on language ).
예시
countBy(1,10) === [1,2,3,4,5,6,7,8,9,10]
countBy(2,5) === [2,4,6,8,10]
countBy(100,3) === [100,200,300]
(1) 먼저 빈 리스트를 정해준다
(2) 최대값을 정한다
(3) i의 값이 계속 증가하지만 그 값이 x에 들어가도록 정한다
(4) 리스트에 들어가도록 하려면 add를 알아야 한다
List<int> countBy(int x, int n) {
List<int> answer = [];
int total = x*n;
for (int i = x; i <=total; i +=x)
answer.add(i);
return answer;
}
Deoxyribonucleic acid, DNA is the primary information storage molecule in biological systems. It is composed of four nucleic acid bases Guanine ('G'), Cytosine ('C'), Adenine ('A'), and Thymine ('T').
Ribonucleic acid, RNA, is the primary messenger molecule in cells. RNA differs slightly from DNA its chemical structure and contains no Thymine. In RNA Thymine is replaced by another nucleic acid Uracil ('U').
Create a function which translates a given DNA string into RNA.
예시
"GCAT" => "GCAU"
"TTT" => "UUU"
"GTCCCG" => "GUCCCG"
(1) replaceAll을 알고 있느냐의 문제다
(2) 문제에서는 G,C,A,T 총 4개의 알파벳만 사용한다는 전제를 깔고 있지만, 코드에서 그 부분에 대한 조건을 넣지는 않았다.
String rnaToDna(String dna) {
return dna.replaceAll('T', 'U');
}
void main() {
print(rnaToDna("TJKKTDCT"));
}
Return the number (count) of vowels in the given string.
We will consider a, e, i, o, u as vowels for this Kata (but not y).
The input string will only consist of lower case letters and/or spaces.
예시
getCount("abcde") === 2
getCount("bbbbcdf") === 0
getCount("aeiou") === 5
(1) split을 사용해서 문자열을 전부 나눈다
(2) fold를 사용해서 결과값을 누적하는법을 알아야 한다
(3) contains 를 사용해서 두개의 문자열을 비교하고 true 일 경우 값을 1씩 더해나가야 한다
import "dart:core";
int getCount(String inputStr){
return inputStr.split('').fold(0, (a, b) => a += 'aeiou'.contains(b) ? 1 : 0 );
}
생성자 파헤치기 (Constructor) (0) | 2023.07.31 |
---|---|
Dart 강의 완강 후기(feat 노마드코더) (0) | 2023.07.04 |
내 맥북에 flutter doctor 찾는법 (feat 더코딩파파) (0) | 2023.07.04 |
Cascade Notation(캐스케이드 표기법) (0) | 2023.07.04 |
Named Parameters / Optional Positional Parameter (0) | 2023.07.02 |