← 수업 제작 도구
홈 › Components › Ordered List (정렬 리스트) › 화면 5

화면 5. Ordered List.indexOfItem [source]

원본: Computation Layer 문서(Ordered List (정렬 리스트)) · Try It (원본 화면)

화면 번호5 / 11
문서 항목 설명 (원문)indexOfIteminitialItemIndex: number Returns the sorted index of the item that started with the given index (indexed starting with 1).

1. 화면 캡처 (빨간 번호 = 아래 표의 번호)

화면 5 캡처

화면에 적힌 영어 문구(원문):

2. CL이 입력된 곳

코드 안의 회색 줄은 원문 영어 주석이고, 파란 줄은 그 영어 주석의 번역이며, 연분홍 줄은 코드가 하는 일의 설명이다.

번호이름종류CL 코드 원문, 번역, 설명
1레이블 없는 메모메모
# Take the current index of the first item (apple = 1) 
# and convert it into a term that makes sentence in line
# with the rest of the note.
▷ 첫 번째 항목(apple = 1)의 현재 위치 번호를 가져와, 메모의 나머지 문장과 어울리는 낱말로 바꾼다.
position = 
  when order1.indexOfItem(1) = 5 ""
  when order1.indexOfItem(1) = 4 "second "
  when order1.indexOfItem(1) = 3 "third "
  when order1.indexOfItem(1) = 2 "fourth "
  otherwise "fifth "
▶ 변수 position은 order1.indexOfItem(1), 즉 처음에 1번째였던 항목이 정렬된 뒤 있는 자리가 5이면 빈 글자, 4이면 "second "(두 번째), 3이면 "third "(세 번째), 2이면 "fourth "(네 번째), 그 밖(1)이면 "fifth "(다섯 번째)로 한다.
order1.indexOfItem(1)은 처음에 1번째였던 항목이 정렬된 뒤 몇 번째 자리에 있는지를 알려 준다. 낱말 뒤에는 공백이 한 칸씩 들어 있다. when은 조건을 차례로 확인해 처음 맞는 값을 쓴다.
# Insert the "position" variable into the note using ${ }. ▷ ${ }를 써서 "position" 변수를 메모에 끼워 넣는다. content: "Order the following fruits from least tasty to most tasty. You said that the apple was the ${position}tastiest. Discuss your opinion with a partner." ▶ 메모의 내용(content)은 "Order the following fruits from least tasty to most tasty."와 "Discuss your opinion with a partner." 사이에 "You said that the apple was the ${position}tastiest."(apple이 ○번째로 맛있다고 했다.)를 넣은 여러 줄 글자로 한다.
position의 값이 "tastiest" 앞에 들어간다. ${ }는 글자 안에 변수의 값을 끼워 넣는 표기이다. content는 메모에 직접 적은 글을 덮어쓴다.