Last active
December 8, 2019 05:49
-
-
Save luislobo14rap/f0ca232c5ab18545dc1b7a5e4e6887f2 to your computer and use it in GitHub Desktop.
setArray.js
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
// arrayToPlain.js v1 | |
function arrayToPlain(array_, columns = 2, heading){ | |
// clone array | |
array__ = array_.join('!@#$%$#@!').split('!@#$%$#@!'); | |
if(heading){ | |
array__ = [...heading, ...array__]; | |
}; | |
let csv = []; | |
let column = 0; | |
let tempArray = []; | |
while(array__.length > 0){ | |
if(column != columns){ | |
column++; | |
tempArray.push(array__.shift()); | |
}else{ | |
csv.push(tempArray.join(' ')); | |
column = 0; | |
tempArray = []; | |
}; | |
}; | |
if(tempArray.length > 0){ | |
csv.push(tempArray.join(' ')); | |
}; | |
return csv; | |
}; |
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
// getArray.js v1 | |
function getArray(key, value){ | |
if( localStorage.getItem('array_' + key) == null ){ | |
return null; | |
}; | |
return localStorage.getItem('array_' + key).split('!@#$%$#@!'); | |
}; |
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
// setArray.js v1 | |
function setArray(key, value){ | |
if(typeof value == 'string'){ | |
value = value.split(', '); | |
}; | |
if( localStorage.getItem('array_' + key) != null ){ | |
let oldValue = localStorage.getItem('array_' + key).split('!@#$%$#@!'); | |
for(let i = 0; i < value.length; i++){ | |
oldValue.push(value[i]); | |
}; | |
value = oldValue; | |
}; | |
value = value.join('!@#$%$#@!'); | |
localStorage.setItem('array_' + key, value); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment