add the ip length test

This commit is contained in:
rloukil 2018-12-28 14:23:03 +01:00
parent c2ec4d1ca1
commit 72da607981

26
app.js
View file

@ -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);
data.forEach(element => { console.log(date);
Ip4OrIp6(element.ip) console.log(ipv4_v6);
})
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,
} }
] ]
}, },