서론
오늘도 화이팅하자구😊😊😊
본론
Sum of positive
You get an array of numbers, return the sum of all of the positives ones.
배열을 받을 것이고 양의 정수들만 더해라. 이거네😊😊
Example [1,-4,7,12] => 1 + 7 + 12 = 20
Note: if there is nothing to sum, the sum is default to 0.
더할게 없으면 0,
어제부터 쉬운 문제만 걸리네😢😢😢
결론
sum을 활용 하여, 배열을 다 더하도록 하면 됨. sumOfPositivies의 numbers 인수는 let이라고 생각하면됨.
그래서!!! newnumbers를 새롭게 정의하여서 numbers의 음의 정수는 0으로 만들어 버리고 newnumbers에 다 대입 한당.
by using append()!! 그리고 이제!!!!!!!!!!!!!!!!!!☺️☺️😊☺️☺️☺️☺️☺️
새로 만든 배열을 reduce함수를 활용하여, 0 부터 차례대로 더하시오!! 하면 완성.
주말마다, 다른 분들이 짠 코드를 다시한번 보면서 공부해보자.!!
'Algorithm > CodeWars' 카테고리의 다른 글
Calculate BMI (0) | 2021.04.02 |
---|---|
Opposite number (0) | 2021.03.31 |
Even or Odd (0) | 2021.03.29 |
Sum of Digits / Digital Root (0) | 2021.03.28 |
Expressions Matter (0) | 2021.03.27 |