diff --git a/practice.js b/practice.js index a9e0f69..2d11e27 100644 --- a/practice.js +++ b/practice.js @@ -28,7 +28,9 @@ */ // Code Here - +function first(array,callback){ + callback(array[0]) +} // Do not edit the code below. var names = ['Aodhan', 'Greg', 'Jake', 'Oscar', 'Aodhan', 'Tanner', 'Greg']; @@ -48,7 +50,9 @@ first(names, function(firstName){ */ //Code Here - +function last(array,callback){ + callback(array[array.length-1]) +} // Do not edit the code below. last(names, function(lastName){ console.log('The last name in names is ' + lastName); @@ -66,7 +70,9 @@ last(names, function(lastName){ */ //Code Here - +function multiply(num1,num2,callback){ + callback(num1*num2) +} // Do not edit the code below. multiply(4, 3, function(answer){ console.log('The answer is ' + answer); //should console.log "The answer is 12" @@ -85,7 +91,14 @@ multiply(4, 3, function(answer){ */ //Code Here - +function contains(array,name,callback){ + if(array.includes(name)){ + callback(true); + } + else { + callback(false); + } +} // Do not edit the code below. contains(names, 'Oscar', function(result){ if(result === true){ @@ -106,7 +119,10 @@ contains(names, 'Oscar', function(result){ */ //Code Here - +function uniq(array,callback){ +var duplicate=array.filter((item,index)=>array.indexOf(item)===index) +callback(duplicate) +} // Do not edit the code below. uniq(names, function(uniqArr){ console.log('The new names array with all the duplicate items removed is ', uniqArr); @@ -123,7 +139,11 @@ uniq(names, function(uniqArr){ */ //Code Here - +function each(array,callback){ + for(var a=0;a