num_elements is not passed as a parameter now, because we can take it from the array directly.
If we repeat an element in the array, it will return -1 (Which is the error code)
function pairs(target_value, array) { var num_elements = array.length; for ( var i = 0; i < num_elements; i++ ) { for ( var j = 0; j < num_elements; j++ ) { if ( i !== j && array[i] === array[j] ) { return -1; } } } return 0; }
function pairs(num_elements, target_value, array) {- function pairs(target_value, array) {
- var num_elements = array.length;
- for ( var i = 0; i < num_elements; i++ ) {
- for ( var j = 0; j < num_elements; j++ ) {
- if ( i !== j && array[i] === array[j] ) {
- return -1;
- }
- }
- }
- return 0;
- }