Update 04_vectors.clj
This commit is contained in:
parent
d8ac41c15f
commit
a55623398f
1 changed files with 10 additions and 10 deletions
|
|
@ -2,32 +2,32 @@
|
|||
(:require [koan-engine.core :refer :all]))
|
||||
|
||||
(meditations
|
||||
"You can use vectors in clojure as array-like structures"
|
||||
"Векторы в Clojure похожи на массивы"
|
||||
(= __ (count [42]))
|
||||
|
||||
"You can create a vector from a list"
|
||||
"Можно их содать из списка"
|
||||
(= __ (vec '(1)))
|
||||
|
||||
"Or from some elements"
|
||||
"Или из ничего"
|
||||
(= __ (vector nil nil))
|
||||
|
||||
"But you can populate it with any number of elements at once"
|
||||
"Число элементов — ваше дело"
|
||||
(= [1 __] (vec '(1 2)))
|
||||
|
||||
"Conjoining to a vector is different than to a list"
|
||||
"Добавляем элемент, помним что вектор «похож» на массив"
|
||||
(= __ (conj [111 222] 333))
|
||||
|
||||
"You can get the first element of a vector like so"
|
||||
"Получаем первый элемент"
|
||||
(= __ (first [:peanut :butter :and :jelly]))
|
||||
|
||||
"And the last in a similar fashion"
|
||||
"Последний элемент"
|
||||
(= __ (last [:peanut :butter :and :jelly]))
|
||||
|
||||
"Or any index if you wish"
|
||||
"Да какой угодно элемент"
|
||||
(= __ (nth [:peanut :butter :and :jelly] 3))
|
||||
|
||||
"You can also slice a vector"
|
||||
"Нарезаем вектор"
|
||||
(= __ (subvec [:peanut :butter :and :jelly] 1 3))
|
||||
|
||||
"Equality with collections is in terms of values"
|
||||
"Коллекции сравниваются по их элементам"
|
||||
(= (list 1 2 3) (vector 1 2 __)))
|
||||
|
|
|
|||
Loading…
Reference in a new issue