Angular Smart 404 Page

Here is the implementation of getThreshold method:Then if we still have any possible entry we sort the dictionary by the Levenshtein distance to the input value..After that, we returning the first value from the sorted dictionary..The source code of sortByDistances method:We created pathsDistance hashmap to store calculated distances values..By doing that we calculate the distance only once for each item in the dictionary..Then we used that mapping to sort the values..The main magic is stored in levenshtein method that holds the algorithm implementation..I took it from the Angular CLI source code as it the most efficient one written in TypeScript:We created the matrix of size N by M, where N is the length of the first string and N is the length of the second one..Then we iterating through the matrix and count the number of operations needed..Afterward, the last cell in the matrix will be the Levenshtein distance between strings..And we are done ????.ConclusionThere is no magic or rocket science to solve real problems that users might face..Using proper algorithms could solve such issues in the elegant and simple way..Next time you start to think about complex solution try to find an existing one that could fit your needs.If you have any feedback, suggestions and crazy ideas — please leave comments or ping me on Twitter.. More details

Leave a Reply