From 3b6e97c5b8e22996524e96a592d52874e5268ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 26 Jan 2020 21:24:38 +0200 Subject: [PATCH] Better end part handling (#2) * Better end part handling * Changes * Fixing typo --- src/pages/index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pages/index.js b/src/pages/index.js index 6a844d4..a946949 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -12,6 +12,8 @@ const IndexPage = () => { // console.log({ osat }) setIp("") if (osat.loppu === "" || osat.loppu.length !== 4) return + if (osat.loppu.slice(0, 1) !== "2" && osat.loppu.slice(0, 1) !== "3") return + if (parseInt(osat.loppu.slice(1)) >= 255 || parseInt(osat.loppu.slice(1)) === 0 || isNaN(parseInt(osat.loppu.slice(1)))) return let ekanumero = "" let loppu = osat.loppu @@ -26,10 +28,10 @@ const IndexPage = () => { } let loppuosa = "" - for (let i of loppu.slice(1)) { - if (i !== "0") { - loppuosa += i - } + loppuosa = loppu.slice(1) + + while(loppuosa.charAt(0) === '0'){ + loppuosa = loppuosa.substr(1) } setIp(`10.22${ekanumero}.${loppuosa}.x`)