Problem 1502. Perl 1: push
This is part of a series of perl function which were very helpful for many perl programmers. Could you implement it in Matlab?
Pushes the values of list onto the end of the array and returns the number of elements in the new array. The output vector should be of the same type (column or row array) as the input vector x regardless of the list append type. Example:
x=[1 2 3 4 5] [x, num]=push(x, [6 7 8])
then
x=[1 2 3 4 5 6 8] [x, num]=8
Solution Stats
Problem Comments
-
4 Comments
All test suites wrongly defined. It should be assert(isequal(num,y_correct))
Why wrongly defined? I will fix it if you can told me what's wrong with the test cases. I saw already cody examples which combines several tests into one assert call. Sure I should call assert(isequal(num,num_correct)) instead of assert(isequal(num,length(y_correct))) but both versions should work (I have already fixed it).
The test cases should test for the correct length of the modified x vector and the correct contents!
I just modified the problem a little bit because functions like assignin seems not to be allowed in cody. It is not my preferred definition of the problem but the problem should be solvable in cody...
Thanks.
Solution Comments
Show commentsProblem Recent Solvers78
Suggested Problems
-
1718 Solvers
-
Calculate the Levenshtein distance between two strings
1420 Solvers
-
276 Solvers
-
Return the first and last characters of a character array
9489 Solvers
-
389 Solvers
More from this Author3
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!