I’m applying for a mid level devloper position.
In order to progress to 2nd interview, you need to pass a technical test. One of the questions was to write a function to work out linux based octal file permissions.
How would yuou guys improve it and tell me why your way is better
using System; using System.Collections; using System.Linq; public class ReadWriteExecute { public static int CalculatePermissionSum(string permString) { int octalPerm = 0; foreach (char permission in permString.ToArray()) { switch (permission) { case 'r': octalPerm += 4; break; case 'w': octalPerm += 2; break; case 'x': octalPerm += 1; break; case '-': octalPerm += 0; break; } } return octalPerm; } public static string SymbolicToOctal(string permString) { string octalPerm = string.Empty; for(int x=0; x<=6;x+=3) { octalPerm += CalculatePermissionSum(new string(permString.Skip(x).Take(3).ToArray())).ToString(); } return octalPerm; } public static void Main(string[] args) { // Should write 752 Console.WriteLine(ReadWriteExecute.SymbolicToOctal("rwx-x--r-")); } }