'use strict';

var PageDetailsController = angular.module('pages.controllers.hmm', [
    'system'
])
    .controller('HmmController', [
        '$scope',
        '$location',
        '$route',
        '$window',
        'System',
        function ($scope,$location, $route,$window,  System) {
            


            $scope.createSuffix = function () {
                $scope.suffixs = [];
                $scope._suffixs = [];
               var sufix = $scope.obrada.text + "$";
               var strLen = sufix.length;
               
                for (var i = 0; i < strLen; i++) {
                    $scope.suffixs.push({id:i,text:sufix.substr(i)})
                }
                $scope.sortiraj();
            };

            //sortiraj

            $scope.sortiraj = function () {
                $scope.suffixs = [];
                $scope._suffixs = [];
                var sufix = $scope.obrada.text + "$";
                var strLen = sufix.length;
                var suffixArray = new Array(strLen);
                var suffixes = new Array(strLen);

                for (var i = strLen - 1; i >= 0; i--) {
                    suffixes[i] = [i, sufix.substr(i)];
                }

                suffixes.sort(function (a, b) {
                    return a[1] < b[1] ? -1 : 1;
                });

                for (var i = 0; i < strLen; i++) {
                    //suffixArray[i] = suffixes[i][0];
                    var c = suffixes[i][0];
                    var d = suffixes[i][1];
                    $scope._suffixs.push({ id: c, text: d })
         
                }          
            }
        
        }
    ]);