6 kyu

Extract the IDs from the data set

1,514 of 2,226jhoffner

Description:

Complete the method so that it returns an array of all ID's passed in. The data structure will be similar to the following:

var data = {
  id: 1,
  items: [
    {id: 2},
    {id: 3, items: [
      {id: 4},
      {id: 5}
    ]}
  ]
}

extractIds(data) // should return [1,2,3,4,5]
data =
  id: 1
  items: [
    {id: 2}
    {id: 3, items: [
      {id: 4}
      {id: 5}
    ]}
  ]


extractIds(data) # should return [1,2,3,4,5]
data = {
  id: 1,
  items: [
    {id: 2},
    {id: 3, items: [
      {id: 4},
      {id: 5}
    ]}
  ]
}

extract_ids(data) # should return [1,2,3,4,5]
extract_ids({}) # should return []

The method should be able to handle the case of empty data being passed in.

Note: The only arrays that need to be traversed are those assigned to the "items" property.

Arrays
Algorithms

Similar Kata:

Stats:

CreatedMar 31, 2013
PublishedApr 2, 2013
Warriors Trained4574
Total Skips829
Total Code Submissions17345
Total Times Completed2226
JavaScript Completions1514
Ruby Completions605
CoffeeScript Completions111
Total Stars85
% of votes with a positive feedback rating89% of 257
Total "Very Satisfied" Votes214
Total "Somewhat Satisfied" Votes31
Total "Not Satisfied" Votes12
Ad
Contributors
  • jhoffner Avatar
  • anter69 Avatar
  • Just4FunCoder Avatar
Ad