File size: 834 Bytes
5fae594
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/** pass me an object with only one child at each level and will return a nodeStack
 *  and pathStack which describes the only possibly descent top-to-bottom
 *  
 *  @param {Object} description eg { a:       {foo:      {a:'target'}}}
 */
function ascentFrom( description ) {

   function onlyMapping(obj) {
      // this for won't loop but it is the most obvious way to extract a 
      // key/value pair where the key is unknown
      for( var i in obj ) {
         return {key:i, node:obj[i]};
      } 
   }   
   
   var ascent = list({key:ROOT_PATH, node:description}),
       curDesc = description;
         
   while( typeof curDesc == 'object' ) {
   
      var mapping = onlyMapping(curDesc);
       
      curDesc = mapping.node;
      
      ascent = cons( mapping, ascent ); 
   }
         
   return ascent;            
}