Link | array_flip_9 |
Author | Jonathan Guthrie |
Category | Array |
Version | 9.x |
License | Public Domain |
Posted | 05 Nov 2010 |
Updated | 06 Nov 2010 |
More by this author... |
Lazy way to reverse the order of key/value pairs in a pair array.
NOTE: This is a Lasso 9 port of Jason Huck's array_flip
http://tagswap.net/array_flip
Also included is a method that extends the Lasso 9 array type, adding ->flip as a member tag. Thanks to Jolle Carlestam for the inspiration :)
var(unflipped = array( 'a' = 1, 'b' = 2, 'c' = 3 ) ) var(flipped = array_flip($unflipped)) 'unflipped: ' + $unflipped 'flipped: ' + $flipped 'l9 method flipped: ' + $flipped->flip &
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
define array_flip(in) => { // Returns the given pair array with the keys and values inverted. local(out = array) with i in #in where #i->isA('pair') do => { #out->insert(#i->second = #i->first) } return #out } // OR define array->flip() => { loop(.size) => { if(.get(loop_count)->isa('pair')) => { .get(loop_count) = pair(.get(loop_count)->second = .get(loop_count)->first) } } }
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft