Exercise - Data Grid (Basic)

by Vijay Venkatan

JavaScript

/**
 * Grid Builder
 * Create a function "gridify" that accepts an array of similar objects
 * It will output a "table" in the console
 * The header row will be the property names and should display ONCE
 * The body rows will be the property values
 *
 * Hint: use tabs to align, "/t" is the tab character
 *
 */

/* your code here */

gridify([
    {name: "Ryan", value: 913},
    {name: "Jimmy", value: 20003},
    {name: "Donna", value: 923}    
]);
function gridify(array)
{
    console.log("Name \t" +  "\tValue");
    for(var i=0;i<array.length;i++)
    {
        console.log(array[i].name + "\t\t" + array[i].value);
    }
}
/*
ex output:
Name      Value
Ryan      913
Jimmy     20003
Donna     923
*/