Write a function that takes a numeric array as its right argument and returns the mean (average) of the array.
your_function 1 2 3 4 5 6
3.5
your_function ⍬ ⍝ the average of an empty vector is 0
0
your_function 17 ⍝ your solution should work with a scalar argument
17
your_function 5 3⍴⍳15 ⍝ and average the columns of a matrix
7 8 9
your_function 3 3 3⍴⍳15 ⍝ or the matrices of a 3D array etc.
5 6 7
8 9 10
6 7 8
Write a function that takes a numeric vector as its right argument and returns the median of the array. The median is the number separating the higher half of the vector from the lower half. The median can be found by arranging all the observations from lowest value to highest value and picking the middle one. If there is an even number of observations, then there is no single middle value; the median is then defined to be the mean of the two middle values.
your_function 1 2 3 4 5 6 7 8 9
5
your_function 1 8 2 7 3 6 4 5
4.5
your_function ⍬
0
your_function ,7
7
Write a function that takes a numeric vector or scalar as its right argument and returns the mode (that is, the most common value) of the array. If more than one number occurs the greatest number of times, return all such numbers.
your_function 2 1 4 3 2 5 1 2
2
your_function ⍬ ⍝ should return an empty vector
your_function 1 2 3 4 1 2
1 2
Write a function that takes vectors as its left and right arguments and returns them “meshed” into a single vector formed by alternately taking successive elements from each argument. The arguments do not have to be the same length.
'MENS' your_function 'EKES'
MEEKNESS
'Dyalog' your_function 'APL'
DAyPaLlog
'APL' your_function 'Dyalog'
ADPyLalog
1 3 5 7 your_function 2 4 6 8 ⍝ should work with numeric vectors
1 2 3 4 5 6 7 8
'' your_function 'Hello' ⍝ either or both arguments could be empty
Hello
Write a function that takes a vector as its right argument and returns elements that occur only once in the vector.
your_function 1 2 3 4 5
1 2 3 4 5
your_function 1 2 3 4 5 4 3 2 1
5
your_function 'hello world'
he wrd
Write a function that takes a vector of vectors as its right argument and returns it sorted by the length of each element. An element of the vector can be scalar or an empty vector.
your_function 'one' 'two' 'three' 'four' 'five' 'six'
┌───┬───┬───┬────┬────┬─────┐
│one│two│six│four│five│three│
└───┴───┴───┴────┴────┴─────┘
your_function (2 4 3) (4 5) 1 (7 3)
┌─┬───┬───┬─────┐
│1│4 5│7 3│2 4 3│
└─┴───┴───┴─────┘
your_function ⍬ ⍝ should return an empty vector
your_function 'one' 2 'three' '' 'four' (5 6 7 8)
┌┬─┬───┬────┬───────┬─────┐
││2│one│four│5 6 7 8│three│
└┴─┴───┴────┴───────┴─────┘
Write a function that takes a numeric vector and returns all elements that are divisible by 3 or 5.
your_function 1 2 3 4 5 6 7 8 9 10
3 5 6 9 10
your_function ⍬ ⍝ should return an empty vector
Write a function that takes a numeric vector and returns a two element vector whose first element contains the values less than 0 (zero) in the vector and the second element contains all values greater than or equal to 0.
your_function 0 1 ¯2 3 ¯4 ¯5 6 7 8 ¯9 10
┌───────────┬──────────────┐
│¯2 ¯4 ¯5 ¯9│0 1 3 6 7 8 10│
└───────────┴──────────────┘
your_function 1 2 3 4 5
┌┬─────────┐
││1 2 3 4 5│
└┴─────────┘
your_function ⍬ ⍝ should return a vector of two empty vectors
┌┬┐
│││
└┴┘
It’s common to encounter delimited text – for example, comma- separated values in a file.
Write a function that takes a character vector as its right argument and one or more characters as its left argument, where those characters are delimiters in the right argument. The function should return the delimited text as a vector of vectors.
',' your_function 'comma,delimited,values'
┌─────┬─────────┬──────┐
│comma│delimited│values│
└─────┴─────────┴──────┘
' ' {your_function} 'break up words'
┌─────┬──┬─────┐
│break│up│words│
└─────┴──┴─────┘
',' {your_function} ','
┌┬┐
│││
└┴┘
Suppose you have a numeric vector that is the list of prices for a set of retail products. You also have a numeric vector that is the number ordered of each product. Write a function that takes as its right argument a vector of prices and as its left argument a numeric vector that indicates the number ordered and returns the total cost for the order. In case you hadn’t realized it, this is an application the dot product. The dot product of two vectors A = [A1, A2, …,An] and B = [B1, B2, …,Bn] is defined as
5 0 2 your_function 2.99 4.99 1.99
18.93
0 0 0 your_function 2.99 4.99 1.99
0