Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<script src="https://unpkg.com/@reactivex/rxjs@5.0.0-beta.7/dist/global/Rx.umd.js"></script>
</body>
</html>
 
const players = {
   player_1: {
     name: 'a',
     carsKeys: {
         car_id_1: true,
         car_id_2: true,
         car_id_3: true
     }
   },
   player_2: {
     name: 'b'
   }
};
const cars = {
  car_id_1: {
      property_1: '111',
      property_2: '11',
   },
  car_id_2: {
    property_1 : '222',
    property_2 : '22'
  },
  car_id_3: {
    property_1 : '333',
    property_2 : '33'
  }
}
const players$ = Rx.Observable.of(players)
  .map(x => players[Object.keys(x).find(x=> x === 'player_1')])
  .map(x => Object.keys(x.carsKeys))
  .switchMap(x => Rx.Observable.from(x))
  .map(x => cars[x])
  ;
let result = []
players$.subscribe(x => {
  result.push(x);
  console.log(result)
})
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers