Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Glow JS 0-01 Associative Array by Timothy Robert Keal **/
- function array_dump_this(element,index,array){
- document.write('<font color="green">a[<font color="red">'+index+'</font>]="<font color="red">'+element+'</font>"</font><br>');
- }
- function array_dump(array){
- array.forEach(array_dump_this)
- }
- function addToArray(array) {
- array.push(prompt("Add items to array or 'q' to stop"));
- if (array[array.length-1] == 'q') {
- array.pop();
- array_dump(array);
- }
- else {
- addToArray(array);
- }
- }
- addToArray([]);
- function addslashes(string) {
- return string.replace(/\\/g, '\\\\').
- replace(/\u0008/g, '\\b').
- replace(/\t/g, '\\t').
- replace(/\n/g, '\\n').
- replace(/\f/g, '\\f').
- replace(/\r/g, '\\r').
- replace(/'/g, '\\\'').
- replace(/"/g, '\\"');
- }
- function unicode_toHex(label=''){
- var ret='';
- var unicode='';
- for(var offset=0;offset<label.length;offset++){
- unicode=parseInt(label.charCodeAt(offset),10).toString(16);
- ret+=parseInt(unicode.length,10).toString(16)+unicode;
- }
- return ret;
- }
- function array_op(mode='set',array='aa',arg_label='',arg_value=1){
- var label=unicode_toHex(arg_label);
- var addr=array;
- var addr_last='';
- var i=0;
- for(var offset=0;offset<label.length;offset++){
- addr_last=addr;
- addr+='['+parseInt(label.substring(offset,offset),16)+']';
- if(eval(addr+'===undefined')
- for(i=0;i<=16;i++)
- eval(addr_last+'.push(\'\');');
- }
- if(eval(addr+'[16]===undefined')
- for(i=0;i<=16;i++)
- eval(addr+'.push(\'\');');
- addr+='[16]';
- switch(mode){
- case 'get':
- return eval(addr);
- break;
- case 'set':
- return eval(addr+'=\''+addslashes(arg_value)+'\'');
- break;
- case 'inc':
- return eval(addr+'+='+arg_value);
- break;
- case 'dec':
- return eval(addr+'-='+arg_value);
- case 'append':
- return eval(addr+'+=\''+addslashes(arg_value)+'\'');
- break;
- case 'seek':
- return addr;
- break;
- default
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement