JavaScript/09-collectStrings.js
// accepts an object and returns an array of all values in the obj that is string
accepts an object and returns an array of all values in the obj that is string
accepts an object and returns an array of all values in the obj that is string
function collectStrings(obj) {
  let newArr = [];
  for (let key in obj) {
    let value = obj[key];
    if (typeof value === "string") {
      newArr.push(value);
    } else if (typeof value === "object" && !Array.isArray(value)) {
      newArr = newArr.concat(collectStrings(value)); 
    }
  }
  return newArr;
}
function collectStrings ( obj ) { let newArr = [ ] ; for ( let key in obj ) { let value = obj [ key ] ; if ( typeof value === "string" ) { newArr . push ( value ) ; } else if ( typeof value === "object" && ! Array . isArray ( value ) ) { newArr = newArr . concat ( collectStrings ( value ) ) ; } } return newArr ; }
accepts an object and returns an array of all values in the obj that is string
accepts an object and returns an array of all values in the obj that is string
// console.log("1️⃣", newArr); // newArr = (3) ["foo", "bar", "baz"] // console.log("2️⃣", newArr);