function list_add(list, newCard) {
      if (typeof newCard === 'string') {
        return list.push(newCard);
      }
      var cardName = newCard['n'],
        cardIndex = listContainsCard(list, cardName);
      if (cardIndex !== -1) {
        list[cardIndex]['q'] += newCard['q'];
      } else {
        // deep clone object when adding to list to avoid pointer issues when
        // incrementing its size if it is duplicated
        list.push(Object.assign({}, newCard));
      }
      return list;

      // Finds the index of a card name within the given deck list
      // Accepts a deck list (array of card objects) and a card name string
      // Returns the index of the card, if found, or -1 otherwise
      function listContainsCard(list, cardName) {
        for (var i = 0; i < list.length; i++) {
          if (list[i]['n'] === cardName) {
            return i;
          }
        }
        return -1;
      }
    }
// Alternatively, if newCard is a string, simply adds the string to the deck list (used for identified['unrecognized'] and identified['unparseable'])
Alternatively, if newCard is a string, simply adds the string to the deck list (used for identified['unrecognized'] and identified['unparseable'])
Alternatively if newCard is a string simply adds the string to the deck list ( used for identified [ ' unrecognized ' ] and identified [ ' unparseable ' ] )
function list_add(list, newCard) {
      if (typeof newCard === 'string') {
        return list.push(newCard);
      }
      var cardName = newCard['n'],
        cardIndex = listContainsCard(list, cardName);
      if (cardIndex !== -1) {
        list[cardIndex]['q'] += newCard['q'];
      } else {
        list.push(Object.assign({}, newCard));
      }
      return list;
      function listContainsCard(list, cardName) {
        for (var i = 0; i < list.length; i++) {
          if (list[i]['n'] === cardName) {
            return i;
          }
        }
        return -1;
      }
    }
function list_add ( list , newCard ) { if ( typeof newCard === 'string' ) { return list . push ( newCard ) ; } var cardName = newCard [ 'n' ] , cardIndex = listContainsCard ( list , cardName ) ; if ( cardIndex !== - 1 ) { list [ cardIndex ] [ 'q' ] += newCard [ 'q' ] ; } else { list . push ( Object . assign ( { } , newCard ) ) ; } return list ; function listContainsCard ( list , cardName ) { for ( var i = 0 ; i < list . length ; i ++ ) { if ( list [ i ] [ 'n' ] === cardName ) { return i ; } } return - 1 ; } }
Alternatively, if newCard is a string, simply adds the string to the deck list (used for identified['unrecognized'] and identified['unparseable'])
Alternatively if newCard is a string simply adds the string to the deck list ( used for identified [ ' unrecognized ' ] and identified [ ' unparseable ' ] )
// deep clone object when adding to list to avoid pointer issues when // incrementing its size if it is duplicated // Finds the index of a card name within the given deck list // Accepts a deck list (array of card objects) and a card name string // Returns the index of the card, if found, or -1 otherwise