Swap
[source]
Swap array by indexes a and b: a to b, b to a ES6 Destructuring Assignment Array Matching [a, b] = [b, a];
Arguments
condition(Function): function(a:Number, b:Number)
Returns
(Function): Returns Function that return new swapped Array.
Examples:
Simple
Action
Recursive
let ap = require('apop/ap');
ap.swap(1, 2)( [1, 2, 3, 4, 5, [6, 7, 8, 9, 10]])
// => [1, 3, 2, 4, 5, [8, 7, 6, 10, 9]]
let swap = require('apop/ap/swap');
swap(1, 2)( [1, 2, 3, 4, 5, [6, 7, 8, 9, 10]])
// => [1, 3, 2, 4, 5, [8, 7, 6, 10, 9]]
let ap = require('apop/ap');
ap.recursive(ap.swap(1, 2))( [1, 2, 3, 4, 5, [6, 7, 8, 9, 10]])
// => [1, 3, 2, 4, 5, [6, 8, 7, 9, 10]]
Interactive Example:
let ap = require('apop/ap'); let formula = ap( ap.swap(3,4), //[1, 2, 3, 5, 4]) ap.swap(1,2), //[1, 3, 2, 4, 5]) ); formula([1, 2, 3, 4, 5]) // => [1, 3, 2, 4, 5]