add the ip length test
This commit is contained in:
parent
c2ec4d1ca1
commit
72da607981
1 changed files with 14 additions and 12 deletions
22
app.js
22
app.js
|
@ -6,39 +6,41 @@ var date = []
|
||||||
var ipv4_v6 = []
|
var ipv4_v6 = []
|
||||||
|
|
||||||
function Ip4OrIp6(ipAddress){
|
function Ip4OrIp6(ipAddress){
|
||||||
console.log(ipAddress)
|
if(ipAddress.length == 39){
|
||||||
console.log(regex.test(ipAddress));
|
ipv4_v6.push(1);
|
||||||
|
}else{
|
||||||
|
ipv4_v6.push(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Refactor getStudents and getScores to return Promise for their response bodies
|
// Refactor getStudents and getScores to return Promise for their response bodies
|
||||||
function getData(){
|
function getData(){
|
||||||
return fetch(`address.json`, {
|
return fetch(`address.json`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json',
|
||||||
}
|
}
|
||||||
}).then((response) => response.json())
|
}).then((response) => response.json())
|
||||||
};
|
};
|
||||||
|
|
||||||
getData().then((data)=>{
|
getData().then((data)=>{
|
||||||
data.forEach(element => {
|
data.forEach(element => {
|
||||||
date.push(element.date)
|
date.push(element.date);
|
||||||
|
Ip4OrIp6(element.ip);
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(date);
|
console.log(date);
|
||||||
|
console.log(ipv4_v6);
|
||||||
|
|
||||||
data.forEach(element => {
|
|
||||||
Ip4OrIp6(element.ip)
|
|
||||||
})
|
|
||||||
console.log(ipv4_v6)
|
|
||||||
var ctx = document.getElementById("myChart").getContext('2d');
|
var ctx = document.getElementById("myChart").getContext('2d');
|
||||||
var chart = new Chart(ctx, {
|
var chart = new Chart(ctx, {
|
||||||
type: 'line',
|
type: 'bar',
|
||||||
data: {
|
data: {
|
||||||
labels:date ,
|
labels:date ,
|
||||||
datasets: [{
|
datasets: [{
|
||||||
label: "Statistics for IPV4 and IPV6",
|
label: "Statistics for IPV4 and IPV6",
|
||||||
data: [1 , -1 , 1 , 1 , -1 , 1,1 , -1 , 1 , 1 , -1 ],
|
data:ipv4_v6,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue