From 97a5070129302538d197cc5280122d5bc6d04efd Mon Sep 17 00:00:00 2001 From: Mario Basic Date: Fri, 19 Jun 2015 13:16:53 +0200 Subject: [PATCH] Improved contains function. --- assets/js/helpers/contains.js | 12 +++++++----- public/js/app.js | 12 +++++++----- public/js/events.js | 12 +++++++----- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/assets/js/helpers/contains.js b/assets/js/helpers/contains.js index 05f2d3ff..272eb620 100644 --- a/assets/js/helpers/contains.js +++ b/assets/js/helpers/contains.js @@ -11,12 +11,14 @@ function contains(line, list) { for (var i = 0; i < lines.length; i ++) { - // If by any chance one line in the list is empty or contains a blank space, ignore it - // It would probably be better to use regex here to detect blank space, but since - // this is not likely to be triggered anyway, there is no need for that yet. - if(lines[i] === '' || lines[i] === ' ') continue; + // Trim all lines from the list one by one + var cleanLine = lines[i].trim(); - if (line.indexOf(lines[i]) > - 1) { + // If by any chance one line in the list is empty, ignore it + if(cleanLine === '') continue; + + // If line contains the clean line return true + if (line.indexOf(cleanLine) > - 1) { return true; } } diff --git a/public/js/app.js b/public/js/app.js index 435c2a94..d150212b 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -960,12 +960,14 @@ function contains(line, list) { for (var i = 0; i < lines.length; i++) { - // If by any chance one line in the list is empty or contains a blank space, ignore it - // It would probably be better to use regex here to detect blank space, but since - // this is not likely to be triggered anyway, there is no need for that yet. - if (lines[i] === '' || lines[i] === ' ') continue; + // Trim all lines from the list + var cleanLine = lines[i].trim(); - if (line.indexOf(lines[i]) > -1) { + // If by any chance one line in the list is empty, ignore it + if (cleanLine === '') continue; + + // If line contains the clean line return true + if (line.indexOf(cleanLine) > -1) { return true; } } diff --git a/public/js/events.js b/public/js/events.js index d70937bb..444fa00e 100644 --- a/public/js/events.js +++ b/public/js/events.js @@ -587,12 +587,14 @@ function contains(line, list) { for (var i = 0; i < lines.length; i++) { - // If by any chance one line in the list is empty or contains a blank space, ignore it - // It would probably be better to use regex here to detect blank space, but since - // this is not likely to be triggered anyway, there is no need for that yet. - if (lines[i] === '' || lines[i] === ' ') continue; + // Trim all lines from the list + var cleanLine = lines[i].trim(); - if (line.indexOf(lines[i]) > -1) { + // If by any chance one line in the list is empty, ignore it + if (cleanLine === '') continue; + + // If line contains the clean line return true + if (line.indexOf(cleanLine) > -1) { return true; } }