push
Appends an element to the end of an array and returns a new array
(push element arr)
Returns
The push
function returns a new array that includes the original elements of the input array followed by the appended element. The push!
function modifies the original array and returns the value
Parameters
element (any) - the element to be added to the array.
arr (array) - the input array to which the element will be appended.
Examples
(push 5 [1, 2])
;;=> [1, 2, 5]
(def arr1 [1, 2, 3])
(push 4 arr1)
;;=> [1, 2, 3, 4]
arr1 ;; arr1 remains the same
;;=> [1, 2, 3]
(push! 5 arr1)
;;=> 5
arr1
;;=> [1, 2, 3, 5]
Was this helpful?