0.0.14 • Published 9 years ago

recursify v0.0.14

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

recursify

Functional programming has gotten bigger. The below functions(mostly built-in to JS) are defined using recursion. Enjoy.

Install

$ npm install recursify

Usage

var R = require('recursify');

R.map(function(x) { return x * 3}, [1,2,3]);

// return [3,6,9];

R

Recursify


R~isString(input) ⇒ boolean

isString Function

Kind: inner method of R

Example

isString('test');
// return true;

R~isArray(input) ⇒ boolean

isArray function

Kind: inner method of R

Example

isArray([1,2,3]);
// return true;

R~isObject(input) ⇒ boolean

isObject function

Kind: inner method of R

Example

isObject({});
// return true;

R~isNumber(input) ⇒ boolean

isNumber function

Kind: inner method of R

Example

isNumber(1);
// return true;

R~isFunction(input) ⇒ boolean

isFunction function

Kind: inner method of R

Example

isFunction(function(){});
// return true;

R~isSimilar(input1, input2) ⇒ boolean

isSimilar function

Kind: inner method of R

Example

isSimilar({}, []);
// return false;

R~isEmpty(input) ⇒ boolean

isEmpty Function

Kind: inner method of R

Example

isEmpty([]);
// return true;

R~exists(value, list) ⇒ boolean

Exists Function

Kind: inner method of R

Example

exists(1, [1,2,3]);
// return true;

Example

exists(1, [2,3]);
// return false;

R~map(func, list) ⇒ array

Recursive Map Function

Kind: inner method of R
Returns: array - New array

Example

map(function(x) { return x * 2; }, [1,2,3]);
// return [2,4,6];

R~each(func, list) ⇒ array

Recursive Each Function

Kind: inner method of R
Returns: array - Input array

Example

var count = 0;
each(function(x) { return count += x; }, [1,2,3]);
// return [1,2,3]
// count => 6;

R~filter(func, list) ⇒ array

Recursive Filter Function

Kind: inner method of R
Returns: array - New filtered array

Example

filter(function(x) { return x < 3; }, [1,2,3]);
// return [1,2];

R~reverse(list) ⇒ array

Recursive Reverse Function

Kind: inner method of R
Returns: array - New reversed array

Example

reverse([1,2,3]);
// return [3,2,1];

R~insert(value, list) ⇒ array

Recursive Insert Function

Kind: inner method of R
Returns: array - New array with inserted value

Example

insert(2, [1,4,5]);
// return [1,2,4,5];

R~insertDesc(value, list) ⇒ array

Recursive Insert Function

Kind: inner method of R
Returns: array - New array with inserted value

Example

insertDesc(3, [4,2,1]);
// return [4,3,2,1];

R~sort(list) ⇒ array

Recursive Sort Function (ascending)

Kind: inner method of R
Returns: array - New sorted array-ascending

Example

sort([1,5,3,3,1,3,5,6]);
// return [1,1,3,3,3,5,5,6];

R~sortDesc(list) ⇒ array

Recursive Sort Function (descending)

Kind: inner method of R
Returns: array - New sorted array-descending

Example

sortDesc([1,4,2,4,1,3]);
// return [4,4,3,2,1,1];

R~qsort(list) ⇒ array

Quick Sort Function (ascending)

Kind: inner method of R
Returns: array - New sorted-unique-ascending

Example

qsort([5,4,1,2,4,1,3,4,6]);
// return [1,2,3,4,5,6];

R~qsortDesc(list) ⇒ array

Quick Sort Function (descending)

Kind: inner method of R
Returns: array - New sorted-unique-descending

Example

qsortDesc([1,5,2,1,3,5,6,7,3]);
// return [7,6,5,3,2,1];

R~foldr(func, value, list) ⇒ *

Recursive Foldr Function

Kind: inner method of R
Returns: * - Result after collecting

Example

foldr(function(x, y) { return x + y; }, 10, [1,2,3]);
// return 16;

R~foldl(func, value, list) ⇒ *

Recursive Foldl Function

Kind: inner method of R
Returns: * - Result after collecting

Example

foldl(function(x, y) { return x + y; }, 10, [1,2,3]);
// return 16;

R~addr(list1, list2) ⇒ array

Recursive Right Concatenation Function

Kind: inner method of R
Returns: array - New array of list1 + list2

Example

addr([1,2,3], [4,5,6]);
// return [1,2,3,4,5,6];

R~addl(list1, list2) ⇒ array

Recursive Left Concatenation Function

Kind: inner method of R
Returns: array - New array of list2 + list1;

Example

addl([1,2,3], [4,5,6]);
// return [4,5,6,1,2,3];

R~rgive(value, list, mutate) ⇒ array

Append value to list

Kind: inner method of R
Returns: array - New array of appended value

Example

rgive(1, [4,3,2]);
// return [4,3,2,1];

R~lgive(value, list, mutate) ⇒ array

Prepend value to list

Kind: inner method of R
Returns: array - New array of prepended value

Example

lgive(1, [2,3,4]);
// return [1,2,3,4];

R~cplist(list) ⇒ array

Copy array (Array.prototype.slice wrapper)

Kind: inner method of R

Example

var a = [1,2,3];
var b = cplist(a);
a == b
// return false;

R~indexOf(match, list, index) ⇒ number

IndexOf Function

Kind: inner method of R
Returns: number - index value if match found. Returns -1 if no match.

Example

indexOf('l', 'hello');
// return 2;

Example

indexOf('a', 'hello');
// return -1;

R~genList(size, function) ⇒ array

genList Function

Kind: inner method of R
Returns: array - New array of generated values

Example

genList(5, function(x) { return x * 3; });
// return [0,3,6,9,12];

R~keys(obj) ⇒ array

keys functions

Kind: inner method of R

Example

keys({a: 1, b: 2});
// return ['a', 'b'];

R~lenObj(obj) ⇒ number

lenObj function

Kind: inner method of R

Example

lenObj({a: 1, b: 2});
// return 2;

R~cpobj(obj) ⇒ object

Copy Object Function

Kind: inner method of R
Returns: object - Copy of object

Example

var a = {hello: 'world'};
var b = cpboj(a);
b === a;
// return false

R~lmerge(obj1, obj2) ⇒ object

Merge Left Function

Kind: inner method of R
Returns: object - obj1

Example

var a = {a: 1};
var b = {b: 2};
lmerge(a, b);
// return {a: 1, b:2};
// a => {a: 1,b: 2};
// b => {b: 2};

R~rmerge(obj1, obj2) ⇒ object

Merge Right Function

Kind: inner method of R
Returns: object - obj2

Example

var a = {a: 1};
var b = {b: 2};
rmerge(a,b);
// return {a: 1,b: 2};
// a => {a: 1};
// b => {a: 1,b: 2};

R~eachObj(func, obj) ⇒ object

EachObj Function

Kind: inner method of R
Returns: object - - input object

Example

var a = {a: 1, b: 2};
var count = 0;
eachObj(function(value, key) { count += value; }, a);
// return {a: 1, b: 2}
// count => 3;

R~mapObj(func, obj) ⇒ object

MapObj Function

Kind: inner method of R
Returns: object - - new object

Example

var a = {a: 1, b: 2}
mapObj(function(value, key, obj) { 
 obj[key + value] = value * 3;
}, a);
// return { a1: 3, b2: 6};

R~foldObj(func, start, obj) ⇒ *

FoldObj Function

Kind: inner method of R

Example

var a = {a: 1, b: 2}
foldObj(function(result, val, key) { return result + val }, 0, a);
// return 3;

R~times(number, function) ⇒ undefined

times Function

Kind: inner method of R

Example

times(3, function(x) { console.log('Number: ', x); });
// return Number: 3
// return Number: 2
// return Number: 1
// return undefined

Contributing

New functions, issues, and pull requests welcome

  1. Fork it
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feature/my-new-feature)
  5. Create a new Pull Request
0.0.14

9 years ago

0.0.13

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago

0.0.0

9 years ago