Skip to content

Instantly share code, notes, and snippets.

@rmariuzzo
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save rmariuzzo/0d351d2aa88c13c39dbe to your computer and use it in GitHub Desktop.

Select an option

Save rmariuzzo/0d351d2aa88c13c39dbe to your computer and use it in GitHub Desktop.

Revisions

  1. rmariuzzo revised this gist Jul 14, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion printlist.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    // Solution proposed for: http://pastebin.com/hjFCZYE7
    // Proposed solution for an exercise given to a friend: http://pastebin.com/hjFCZYE7

    function printList(linePrefix, list) {
    for (var i = 0; i < list.length; i++) {
  2. rmariuzzo created this gist Jul 14, 2014.
    15 changes: 15 additions & 0 deletions printlist.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // Solution proposed for: http://pastebin.com/hjFCZYE7

    function printList(linePrefix, list) {
    for (var i = 0; i < list.length; i++) {
    if (typeof list[i] === 'string') {
    console.log(linePrefix + '.' + i + ': ' + list[i]);
    } else {
    printList(linePrefix + '.' + i, list[i]);
    }
    }
    }


    var sample = ["Red",["Yellow","Green","Blue"],"Black",[["Orange","Purple"],"White"]];
    printList('Test', sample);