Split the url parameter with a Javascript program

Our Own Score

The url parameter containing the repeated parameters is stripped under below javascript function, or if an optional item being passed in it will delete the parameters of the entire url according to the optional value.

function stripUrlParams(url, paramsToStrip){
	
  if(url == null)
	  return
  let arr
  let str = url.split('?')
  if(str[1] != undefined)
	  arr = str[1].split('&')
  else
	  return url
  
  let target = ''
  let already = ''
  let count = 0
  let replace
  let arr2 = []
  
  if(paramsToStrip != null) {
	  for(let j = 0; j < paramsToStrip.length; j++) {
		  
			replace = paramsToStrip[j] + "="
			
			for(let i = 0; i < arr.length; i++) {
				
				if(arr[i].substring(0, 2) == replace) {
					 arr[i] = 'done'
						
				} 
				
			}
				
		  }
		 while(arr.includes('done'))  {
			  
			  if(arr[count] == 'done') {
				  arr.splice(count, 1)
			  } else {
				  count++
			  }
		  }
		 count = 0
  }
 
 for(let i = 0; i < arr.length; i++) {
	  
	  target = arr[i].split('=')[0]
	  
	  for(let j = i + 1; j < arr.length; j++) {
		  next = arr[j].split('=')[0]
		  if(next == target && already != target)
			  arr[j] = 'done'
		  else
			  continue
		  
	  }
	  already = target
}
 
 while(arr.includes('done'))  {
	  
	  if(arr[count] == 'done') {
		  arr.splice(count, 1)
	  } else {
		  count++
	  }
}
  return str[0] + "?" + arr.join('&')

}
0

Leave a Reply

avatar
  Subscribe  
Notify of