function [predictedValue] = ABE010by3(testset, dataset, currentPreProcessor)

% this function finds the closest instance
% then returns the predicted value
predictedValue = [];
featureSize = size(dataset,2);
testSize = size(testset,1);

% firstly normalize the row and data
if strcmp(currentPreProcessor, 'normalize') ~= 1
    myTempToNormalize = [testset;dataset];
    myTempToNormalize = myNormalizer(myTempToNormalize);
    testset = myTempToNormalize(1:testSize,:);     % store normalized test data
    myTempToNormalize(1:testSize,:) = [];        % delete test data
    dataset = myTempToNormalize;
end

% kValue is 5 in that case, but check if dataset has less than 5 instances
if size(dataset,1) < 5
    kValue = size(dataset,1);
else
    kValue = 5;
end

% do for every instance in the test set
tempDataset = dataset;
for testIndex = 1:testSize
    myRow = testset(testIndex,:);
    % below array keeps the kNN effort values
    kEffort = zeros(kValue,1);
    
    for counter = 1:kValue
        
        % initially let the first instance have the best distance
        bestDist = sqrt(sum(abs(myRow(1,1:(featureSize-1)) - dataset(1,1:(featureSize-1))).^2));
        bestIndex = 1;
        
        for i=2:size(dataset,1)
            tempDist = sqrt(sum(abs(myRow(1,1:(featureSize-1)) - dataset(i,1:(featureSize-1))).^2));
            if tempDist < bestDist
                bestDist = tempDist;
                bestIndex = i;
            end
        end
        
        % save the effort value of the closest neighbor
        kEffort(counter,1) = dataset(bestIndex,featureSize);
        
        % delete the closest neighbor for the next run (if there is any)
        dataset(bestIndex,:) = [];
        
    end
    
    %restore dataset
    dataset = tempDataset;
    % return the median of the kNN
    predictedValue = [predictedValue median(kEffort)];
    
end


end