Created
          January 31, 2017 06:12 
        
      - 
      
 - 
        
Save ConnerAiken/25471ca3c85123221a3401dc59772d3c to your computer and use it in GitHub Desktop.  
    An interview question with amazon
  
        
  
    
      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
    
  
  
    
  | var str = '/var/www/./../html/.././webkit'; | |
| var str2 = './var/www/./html/testdir/../assets/.'; | |
| function normalizeUnix(string) { | |
| var arr = string.split('/'); | |
| if(arr[0] == '') | |
| arr.splice(0, 1); | |
| for(var i = 0; i < arr.length; i++) { | |
| if(arr[i] == '.') { | |
| arr.splice(i, 1); | |
| i--; | |
| }else if(arr[i] == '..') { | |
| i--; | |
| arr.splice(i, 2); | |
| i--; | |
| } | |
| } | |
| return arr; | |
| } | |
| console.log(normalizeUnix(str)); | |
| console.log(normalizeUnix(str2)); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
I was asked this question during a phone interview with amazon for a web development position.
I let my nerves get the best of me..