Cody

Problem 980. Unique values without using UNIQUE function

Solution 151766

Submitted on 19 Oct 2012 by David Hruska
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
%% filetext = fileread('your_fcn_name.m') assert(isempty(strfind(filetext, 'unique'))) assert(isempty(strfind(filetext, 'stable'))) A = [9 2 9 5]; assert(isequal(your_fcn_name(A),unique(A,'stable')))

filetext = function x = your_fcn_name(x) to_remove = []; for i = 1:numel(x) if any(x(i) == x(1:i-1)) to_remove(end+1)=i; end end x(to_remove) = []; end %This code written by profile_id 1904570

2   Pass
%% x = [42 1 1 1 42 17 17]; assert(isequal(your_fcn_name(x),unique(x,'stable')))

3   Pass
%% x = rand(1,25); assert(isequal(your_fcn_name(x),unique(x,'stable')))