Map a set with it's index

48 Views Asked by At

Let's say I have the set:

$$ A = \{1,2,3,4\} $$

How would I express something like this:

A.map(function (number, index, set) {
    return number - set[set.length - index - 1]]
});

Which would result in:

$$ B = \{-3, -1, 1, 3\} $$

1

There are 1 best solutions below

0
On BEST ANSWER

You might need an ordered set, $(a_0,a_1,\dots,a_{N-1})$. Then, I guess, your function would return for a given $i$,

$$ a_i - a_{N-1-i}. $$

Is that what you are looking for?