/* ======================================================================
DESC: various methods to simplify

PLATFORMS: 

USAGE NOTES: 
====================================================================== */

/* ======================================================================
FUNCTIONS: 	deSpace()
				dropParen()
		out()
INPUT:		
				
RETURNS:		result, result, boolean

DESC:							
====================================================================== */

/*======================================================================
	deSpace(TEXT)
	
	Description: 
	     Removes (single) spaces from an expression (TEXT). Two spaces in a row turn to one.
	     
	
====================================================================== */
function deSpace(text) {
	for ( var i=0; i<text.length; i++ ) {
    if ( text.charAt(i)==' ' ) {
       text = text.substring(0,i) + text.substring(i+1,text.length);
       i--
    }}
   
  return text 
	
}


/*======================================================================
	dropParen()
	
	Description: 
	     Removes any outside parentheses. 
	     

====================================================================== */
function dropParen(text) {
	if ( out(text) ) {
	
    text = text.substring(1,text.length-1);
 }
return text	
}


/*======================================================================
	out()
	
	Description: 
	     boolean: checks to see if there are outside parentheses
	
====================================================================== */
function out(text) {
	var left = 0;
if ( (text.charAt(0)=='(' && text.charAt(text.length - 1) == ')' ) || (text.charAt(0)=='[' && text.charAt(text.length - 1) == ']' ) )   {
	for ( var i=0; i<text.length-1; i++ ) {
    if ( text.charAt(i)=='(' || text.charAt(i)=='[' ) {
       left++
    }
   if ( text.charAt(i)==')' || text.charAt(i)==']' ) {
      left--
   }
   if ( left == 0 ) {
      break
   }
 }
 if ( left == 0 ) {
    return false
 }
 else {
  return true  
 }
 }
else {return false}
}

