forked from yui/yui3-gallery
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gallery-2012.12.12-21-11 solmsted gallery-array-unnest
- Loading branch information
Showing
19 changed files
with
641 additions
and
49 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,36 @@ | ||
YUI.add('gallery-array-unnest', function(Y) { | ||
YUI.add('gallery-array-unnest', function (Y, NAME) { | ||
|
||
/** | ||
* Utility function that flattens nested arrays. | ||
* @module gallery-array-unnest | ||
*/ | ||
(function (Y) { | ||
'use strict'; | ||
|
||
/** | ||
* Utility function that flattens nested arrays. | ||
* The original array is not modified. The returned array items are a | ||
* shallow copy of the original array items. | ||
* Utility function that flattens nested arrays. The original array is not | ||
* modified. The returned array items are a shallow copy of the original | ||
* array items. | ||
* @for Array | ||
* @method unnest | ||
* @param {Array} array | ||
* @param {Number} levels Optional. If defined, must be a non-negative | ||
* integer. Defaults to 1. | ||
* @returns {Array} | ||
* @param {Number} [levels=1] If defined, must be a non-negative integer. | ||
* @return {Array} | ||
* @static | ||
*/ | ||
var unnest = function (array, levels) { | ||
var _unnest = function (array, levels) { | ||
var empty = []; | ||
|
||
array = empty.concat.apply(empty, array); | ||
|
||
if (levels && levels - 1) { | ||
return unnest(array, levels - 1); | ||
return _unnest(array, levels - 1); | ||
} | ||
|
||
return array; | ||
}; | ||
|
||
Y.Array.unnest = unnest; | ||
}(Y)); | ||
|
||
Y.Array.unnest = _unnest; | ||
}(Y)); | ||
|
||
}, 'gallery-2012.06.20-20-07' ,{requires:['yui'], skinnable:false}); | ||
}, 'gallery-2012.12.12-21-11', {"requires": ["yui-base"]}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,36 @@ | ||
YUI.add('gallery-array-unnest', function(Y) { | ||
YUI.add('gallery-array-unnest', function (Y, NAME) { | ||
|
||
/** | ||
* Utility function that flattens nested arrays. | ||
* @module gallery-array-unnest | ||
*/ | ||
(function (Y) { | ||
'use strict'; | ||
|
||
/** | ||
* Utility function that flattens nested arrays. | ||
* The original array is not modified. The returned array items are a | ||
* shallow copy of the original array items. | ||
* Utility function that flattens nested arrays. The original array is not | ||
* modified. The returned array items are a shallow copy of the original | ||
* array items. | ||
* @for Array | ||
* @method unnest | ||
* @param {Array} array | ||
* @param {Number} levels Optional. If defined, must be a non-negative | ||
* integer. Defaults to 1. | ||
* @returns {Array} | ||
* @param {Number} [levels=1] If defined, must be a non-negative integer. | ||
* @return {Array} | ||
* @static | ||
*/ | ||
var unnest = function (array, levels) { | ||
var _unnest = function (array, levels) { | ||
var empty = []; | ||
|
||
array = empty.concat.apply(empty, array); | ||
|
||
if (levels && levels - 1) { | ||
return unnest(array, levels - 1); | ||
return _unnest(array, levels - 1); | ||
} | ||
|
||
return array; | ||
}; | ||
|
||
Y.Array.unnest = unnest; | ||
}(Y)); | ||
|
||
Y.Array.unnest = _unnest; | ||
}(Y)); | ||
|
||
}, 'gallery-2012.06.20-20-07' ,{requires:['yui'], skinnable:false}); | ||
}, 'gallery-2012.12.12-21-11', {"requires": ["yui-base"]}); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"builds": { | ||
"gallery-array-unnest": { | ||
"jsfiles": [ | ||
"array-unnest.js" | ||
] | ||
} | ||
}, | ||
"name": "gallery-array-unnest" | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"author": [ | ||
"solmsted" | ||
], | ||
"description": "Utility function that flattens nested arrays.", | ||
"displayName": "Gallery: Array Unnest", | ||
"name": "gallery-array-unnest", | ||
"tags": [ | ||
"array", | ||
"flatten", | ||
"gallery", | ||
"nest", | ||
"nested", | ||
"solmsted", | ||
"unnest" | ||
], | ||
"use": [ | ||
"gallery-array-unnest" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<div class="intro"> | ||
<p> | ||
Utility function that flattens nested arrays. | ||
</p> | ||
</div> | ||
|
||
{{>getting-started}} | ||
|
||
<h2> | ||
Description | ||
</h2> | ||
|
||
<p> | ||
`Y.Array.unnest` is a utility function that flattens nested arrays. The nesting depth can be specified. For example: | ||
</p> | ||
|
||
``` | ||
var array = [1, 2, [3, 4, 5], [6, [7, [8, 9]]]]; | ||
|
||
Y.Array.unnest(array, 3); // returns [1,2,3,4,5,6,7,8,9] | ||
Y.Array.unnest(array, 2); // returns [1,2,3,4,5,6,7,[8,9]] | ||
Y.Array.unnest(array, 1); // returns [1,2,3,4,5,6,[7,[8,9]]] | ||
``` | ||
|
||
<p> | ||
The original array is not modified. The returned array items are a shallow copy of the original array items. | ||
</p> | ||
|
||
<h2> | ||
What about `Y.Array.flatten`? | ||
</h2> | ||
|
||
<p> | ||
`Y.Array.flatten` does basically the same thing, is already part of `array-extras`, it can flatten to unknown depths, and it runs faster in the most common use cases. Please use `Y.Array.flatten` | ||
instead of `Y.Array.unnest`. With that being said there are still some semi-valid reasons to use `Y.Array.unnest`. | ||
</p> | ||
|
||
<ul> | ||
<li> | ||
Use `Y.Array.unnest` if you have to stop flattening at a known depth. | ||
</li> | ||
<li> | ||
`Y.Array.unnest` performs better than `Y.Array.flatten` on really really big arrays. | ||
</li> | ||
<li> | ||
`Y.Array.unnest` performs better than `Y.Array.flatten` in some older browsers. | ||
</li> | ||
<li> | ||
Use `Y.Array.unnest` if you enjoy being alternative. | ||
</li> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
shifter [info] revving up | ||
shifter [info] looking for build.json file | ||
shifter [info] found build.json file, shifting | ||
shifter [info] putting the hammer down, let's build this thing! | ||
shifter [info] munging in loader meta data into build.json | ||
shifter [info] putting the hammer down | ||
shifter [info] shifting into gear for gallery-array-unnest | ||
shifter [info] deleting build dir: /build/gallery-array-unnest | ||
shifter [queu] writing RAW file | ||
shifter [queu] compressing gallery-array-unnest/gallery-array-unnest.js with UglifyJS | ||
shifter [queu] writing -min file | ||
shifter [info] shifting for coverage | ||
shifter [info] shifting assets for gallery-array-unnest | ||
shifter [queu] coverage file read, starting coverage for: gallery-array-unnest/gallery-array-unnest.js | ||
shifter [info] istanbul providing coverage | ||
shifter [queu] instrumenting with istanbul | ||
shifter [queu] writing coverage file to gallery-array-unnest/gallery-array-unnest-coverage.js | ||
shifter [info] done racing, the gears are toast | ||
shifter [info] finished in 0.039 seconds, pretty fast huh? |
Oops, something went wrong.