Get started with app development : 'map( )' and 'filter( )'

Hojun Jeong·2022년 7월 14일
0

AppDevelopment

목록 보기
1/2

Week 1

Since this week, I've started Sparta Coding club to learn some java and application development.

As this week is the first week of the learning club, basic grammar for writing java scripts is the main topic for the lecture.

Since I had experience learning some python, C#, and Matlab, I thought basic grammar seemed easy.

However, the Assignment for map and filter is not easy even for me...

Even though there are some trials and errors in writing and debugging a code, the lecture is fascinating. I'm very excited to encounter more challenges and get a solution for making small applications.

=================================================================

map( ), filter( )

Today, I learned "map" to count some specific elements and "filter" to make a new array fulfilled with particular elements. The code is as follows:

# Set the fruit list with many kinds of fruit
let fruit_list = ['사과','감','감','배','포도','포도','딸기',
'포도','감','수박','딸기']
# Code to count the number of specific element ('딸기')
let count= 0;
fruit_list.map((f)=>{
    if(f=='딸기') count+=1
})
console.log(count)
# Code to make new array fulfilled with particular element ('포도')
let podo_list = fruit_list.filter(f => f=='포도')
console.log(podo_list)
profile
Rehabilitation Engineering Researcher

0개의 댓글