0% found this document useful (0 votes)
10 views39 pages

Topalian JavaScript Address Book by Christopher Topalian

Learn to sort an array of objects in JavaScript. This JavaScript Address Book Application teaches many important computer science concepts. https://github.com/ChristopherTopalian/Topalian_Address_Book
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views39 pages

Topalian JavaScript Address Book by Christopher Topalian

Learn to sort an array of objects in JavaScript. This JavaScript Address Book Application teaches many important computer science concepts. https://github.com/ChristopherTopalian/Topalian_Address_Book
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Topalian

JavaScript
Address
Book
by
Christopher Andrew Topalian
All Rights Reserved
Copyright 2000-2023
Dedicated
to
God the Father
<!-- Dedicated to God the Father -->

<!-- All Rights Reserved Christopher Topalian


Copyright 2000-2023 -->

<!-- https://github.com/ChristopherTopalian --
>

<!--
https://github.com/ChristopherAndrewTopalia
n -->

<!-- Topalian_JavaScript_Address_Book.html
-->

<!-- Version 001 -->

<html>
<head>
<title> Topalian JavaScript Address Book
</title>

<link rel = "stylesheet" href =


"css/style001.css">

<script src = "data/info.js"></script>

<script>

function showData(whichArray,
whichLocation)
{
let theText = "";

theText += "<textarea id = 'theTextId' style =


'width: 98%; height: 65%; padding-left: 20px;
padding-right: 20px; padding-top: 10px;
padding-bottom: 10px; background-color:
rgb(40, 40, 40); font-size: 20px; color:
rgb(255, 255, 255);'>";

theText += "info = [\n{ ";

for (let x = 0; x < whichArray.length; x++)


{
theText += "\n";
theText += "\"name\":" + '\"' +
whichArray[x].name+'\",';

theText += '\n';
theText += "\"phoneCell\":" + '\"' +
whichArray[x].phoneCell+'\",';

theText += '\n';
theText += "\"address\":" + '\"' +
whichArray[x].address+'\",';

theText += '\n';
theText += "\"city\":" + '\"' +
whichArray[x].city+'\",';

theText += '\n';
theText += "\"state\":" + '\"' +
whichArray[x].state+'\",';

theText += '\n';
theText += "\"category\":" + '\"' +
whichArray[x].category+'\",';

theText += '\n';
theText += "\"rating\":" + '\"' +
Number(whichArray[x].rating)+'\",';
theText += '\n';
theText += "\"date\":" + '\"' +
whichArray[x].date+'\",';

if (x < whichArray.length - 1)
{
theText += '\n},\n{';
}
}

if (whichLocation == "window")
{
theText += '\n} \n];';

let reportWindow = window.open("",


"Report Window", "left = 10 top = 10, width =
1200, height = 700", true);
reportWindow.document.open();

reportWindow.document.write(theText);

reportWindow.document.body.style.backgrou
nd = "rgb(40, 40, 40)";

reportWindow.document.close();
}

else if (whichLocation == "page")


{
theText += '\n} \n];';

document.getElementById("theData").innerH
TML = theText;
}
}

function downloadText()
{
let theContent =
document.getElementById("theTextId").value;

let dataString = "data:text/json;charset=utf-


8," + encodeURIComponent(theContent);

let downloadAnchor =
document.getElementById("theDownloadAnc
hor");

downloadAnchor.setAttribute("href",
dataString);
downloadAnchor.setAttribute("download",
"info.js");

downloadAnchor.click();
}

function sortByDate(whichArray,
whichDirection)
{
// ascending
if (whichDirection == "up")
{
whichArray.sort(function(a, b)
{
return new Date(a.date) - new
Date(b.date);
});
}
// descending
else if (whichDirection == "down")
{
whichArray.sort(function(b, a)
{
return new Date(a.date) - new
Date(b.date);
});
}
}

function sortByRating(whichArray,
whichDirection)
{
// ascending
if (whichDirection == "up")
{
whichArray.sort(function(a, b)
{
return parseFloat(a.rating) -
parseFloat(b.rating);
});
}

// descending
else if (whichDirection == "down")
{
whichArray.sort(function(b, a)
{
return parseFloat(a.rating) -
parseFloat(b.rating);
});
}
}
function sortByName(whichArray,
whichDirection)
{
// ascending
if (whichDirection == "up")
{
whichArray.sort(function(a, b)
{
return
a.name.localeCompare(b.name);
});
}

// descending
else if (whichDirection == "down")
{
whichArray.sort(function(b, a)
{
return
a.name.localeCompare(b.name);
});
}
}

function
sortByNameAndCategory(whichArray,
whichDirection)
{
whichArray.sort(function(a, b)
{
// ascending
if (whichDirection === "up")
{
return a.name.localeCompare(b.name)
|| a.category.localeCompare(b.category);
}
// descending
else if (whichDirection === "down")
{
return b.name.localeCompare(a.name)
|| b.category.localeCompare(a.category);
}
});
}

function sortByCity(whichArray,
whichDirection)
{
// ascending
if (whichDirection == "up")
{
whichArray.sort(function(a, b)
{
return a.city.localeCompare(b.city);
});
}

// descending
else if (whichDirection == "down")
{
whichArray.sort(function(b, a)
{
return a.city.localeCompare(b.city);
});
}
}

function sortByState(whichArray,
whichDirection)
{
// ascending
if (whichDirection == "up")
{
whichArray.sort(function(a, b)
{
return a.state.localeCompare(b.state);
});
}

// descending
else if (whichDirection == "down")
{
whichArray.sort(function(b, a)
{
return a.state.localeCompare(b.state);
});
}
}
function sortByCityAndState(whichArray,
whichDirection)
{
whichArray.sort(function(a, b)
{
// ascending
if (whichDirection === "up")
{
return a.city.localeCompare(b.city) ||
a.state.localeCompare(b.state);
}
// descending
else if (whichDirection === "down")
{
return b.city.localeCompare(a.city) ||
b.state.localeCompare(a.state);
}
});
}

function reverseArray(whichArray)
{
whichArray.reverse();
}

function stringifyIt(whichArray, whichId)


{

document.getElementById(whichId).innerHT
ML = JSON.stringify(whichArray);
}

</script>

</head>
<body onload = "showData(info,
'page');"></body>

<hr>
<center>
<div class = "textTitle">
TOPALIAN JAVASCRIPT ADDRESS BOOK
</div>
</center>
<hr>

<center>

Sort By:
<button onclick = "sortByName(info, 'up');
showData(info, 'page');" class =
"buttonMenu"> Name </button>
<button onclick =
"sortByNameAndCategory(info, 'up');
showData(info, 'page');" class =
"buttonMenu"> Name & Category </button>

<button onclick = "sortByRating(info, 'up');


showData(info, 'page');" class =
"buttonMenu"> Rating </button>

<button onclick = "sortByDate(info, 'up');


showData(info, 'page');" class =
"buttonMenu"> Date </button>

<button onclick = "sortByCity(info, 'up');


showData(info, 'page');" class =
"buttonMenu"> City </button>
<button onclick = "sortByState(info, 'up');
showData(info, 'page');" class =
"buttonMenu"> State </button>

<button onclick = "sortByCityAndState(info,


'up'); showData(info, 'page');" class =
"buttonMenu"> City & State </button>

<hr>

<button onclick = "reverseArray(info);


showData(info, 'page');" class =
"buttonMenu"> Reverse </button>

<hr>

<button onclick = "downloadText();" class =


"buttonMenu"> Download </button>
<button onclick = "showData(info, 'window');"
class = "buttonMenu"> Report in Window
</button>

<button onclick = "stringifyIt(info,


'theTextId');" class = "buttonMenu">
JSON.stringify </button>
<hr>

<div id = "theData"></div>

<hr>

<a id = "theDownloadAnchor" style =


"display: none"></a>

</center>
</body>

</html>
/* Dedicated to God the Father */

/* All Rights Reserved Christopher Topalian


Copyright 2000-2023 */

/* https://github.com/ChristopherTopalian */

/*
https://github.com/ChristopherAndrewTopalia
n */

/* style001.css */

body
{
background-color: rgb(40, 40, 40);
color: rgb(255, 255, 255);
}
.buttonMenu
{
padding-left: 10px;
padding-right: 10px;
background-color: rgb(0, 0, 0);
border-style: solid;
border-width: 1px;
border-radius: 8px;
font-family: arial;
font-size: 16px;
font-weight: bold;
color: rgb(255, 255, 255);
text-align: center;
}

.buttonMenu:hover
{
border-color: rgb(0, 255, 255);
}

.buttonMenu:active
{
position: relative;
top: 1px;
color: rgb(0, 255, 255);
}

.textTitle
{
position: relative;
top: 4px;
padding-bottom: 5px;
font-family: tahoma;
font-size: 30px;
font-weight: bold;
color: rgb(255, 255, 255);
}
// Dedicated to God the Father

// All Rights Reserved Christopher Topalian


Copyright 2000-2023

// https://github.com/ChristopherTopalian

//
https://github.com/ChristopherAndrewTopalia
n

// info.js

let info =
[
{
name: "James",
phoneCell: "555-555-5551",
address: "17 Galaxy Lane",
city: "Long Beach",
state: "California",
category: "family",
rating: 4,
date: "05/10/1980 07:17 AM"
},

{
name: "Zoe",
phoneCell: "555-555-5552",
address: "234 Oak Road",
city: "Orlando",
state: "Florida",
category: "family",
rating: 3,
date: "07/05/2022 09:00 AM"
},
{
name: "Sandra",
phoneCell: "555-555-5553",
address: "132 River Street",
city: "Bonita Springs",
state: "Florida",
category: "friend",
rating: 5,
date: "08/05/1990 05:00 PM"
},

{
name: "Brandi",
phoneCell: "555-555-5554",
address: "22 Ocean Ave",
city: "Garden Grove",
state: "California",
category: "friend",
rating: 5,
date: "09/08/2023 1:00 AM"
},

{
name: "Repair Shop Central",
phoneCell: "555-555-5555",
address: "217 Main Street",
city: "Riverside",
state: "California",
category: "mechanic",
rating: 2,
date: "02/02/1993 12:17 PM"
},

{
name: "Donald",
phoneCell: "555-555-5556",
address: "77 University Road",
city: "Orlando",
state: "Florida",
category: "friend",
rating: 2,
date: "05/20/1997 02:20 PM"
},

{
name: "Jane",
phoneCell: "555-555-5557",
address: "107 Sky Road",
city: "Paris",
state: "Texas",
category: "friend",
rating: 4,
date: "10/25/1997 04:00 PM"
},

{
name: "Jennifer",
phoneCell: "555-555-5558",
address: "117 Sky Road",
city: "Paris",
state: "Texas",
category: "friend",
rating: 5,
date: "10/25/1997 04:00 PM"
}
];
True Artificial Intelligence System
16-Gon
Tautology
MI 1111 CI
1101 1011
AND XNOR
0001 1001
LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
Contra-
0100 0010
-diction
0000
For More Tutorials:
CollegeOfScripting.weebly.com

CollegeOfScripting.wordpress.com

Youtube.com/ScriptingCollege

Twitter.com/CollegeOfScript

GitHub.com/ChristopherTopalian

GitHub.com/ChristopherAndrewTopalian

Sites.google.com/view/CollegeOfScripting
Dedicated to God the Father
This book is created by the
College of Scripting Music & Science.
Always remember, that each time you write a script
with a pencil and paper, it becomes imprinted so
deeply in memory that the material and methods are
learned extremely well.
When you Type the scripts, the same is true. The
more you type and write out the scripts by keyboard
or pencil and paper, the more you will learn
programming!
Write and Type every example that you find.
Keep all of your scripts organized.
Every script that you create increases your
programming abilities.
SEEING CODE, is one thing,
but WRITING CODE is another.
Write it, Type it, Speak It, See It, Dream It.
CollegeOfScripting.weebly.com

You might also like