Last active
March 31, 2017 15:27
-
-
Save Kaylebor/f0d8dfd03f1bcee2e7a56ea569bc28bc to your computer and use it in GitHub Desktop.
Processing of arrays of strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Checks if a string is contained inside the given array of strings | |
* If the second variable is a string, it just compares them | |
* If the second variable is neither string or array, it returns false */ | |
function checkIfStringInArray(str, arr) { | |
if (typeof arr === 'string') | |
return str === arr; | |
if (arr.constructor && arr.constructor === Array) | |
for (var i in arr) { | |
if (str === arr[i]) { | |
return true; | |
} | |
} | |
return false; | |
} | |
//Accepts an array of arrays of strings, and returns a single array of unique strings | |
function concatMultiDimensionalStrArr(strArr) { | |
var finArr = [] | |
for (var i in strArr) { | |
for (var j in strArr) { | |
if (!checkIfStringInArray(strArr[i][j], finArr) && strArr[i][j]) { | |
finArr.push(strArr[i][j]) | |
} | |
} | |
} | |
return finArr | |
} | |
//Accepts an array of strings, and returns a single array of unique strings | |
function concatStrArr(strArr) { | |
var finArr = [] | |
for (var i in strArr) { | |
if (!checkIfStringInArray(strArr[i], finArr) && strArr[i]) { | |
finArr.push(strArr[i]) | |
} | |
} | |
return finArr | |
} | |
function escapeQuotes(array) { | |
var int_arr = []; | |
for (var i in array) { | |
int_arr.push(array[i].trim().replace('\'','\\\'')); | |
} | |
return int_arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment