Cody

Solution 2016451

Submitted on 12 Nov 2019 by Asif Newaz
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
x = [1:1:5]; a = 4.3; y_correct = 4; assert(isequal(nearestNumber(x,a),y_correct))

x = 3.3000 2.3000 1.3000 0.3000 0.7000 x1 = 4 y = 4

2   Pass
x = [2 4 5 6 8 10]; a = 4.6; y_correct = 5; assert(isequal(nearestNumber(x,a),y_correct))

x = 2.6000 0.6000 0.4000 1.4000 3.4000 5.4000 x1 = 3 y = 5

3   Pass
x = [-2 -3 -1 0]; a = -3.1; y_correct = -3; assert(isequal(nearestNumber(x,a),y_correct))

x = 1.1000 0.1000 2.1000 3.1000 x1 = 2 y = -3