diff --git a/practice.js b/practice.js index a9e0f69..8c073a8 100644 --- a/practice.js +++ b/practice.js @@ -28,7 +28,14 @@ */ // Code Here +// var ourArr = [1,2,3]; +function first(array, callback){ + for(i in array){ + callback(array[0]); + } +} +// first(ourArr); // Do not edit the code below. var names = ['Aodhan', 'Greg', 'Jake', 'Oscar', 'Aodhan', 'Tanner', 'Greg']; @@ -48,6 +55,11 @@ first(names, function(firstName){ */ //Code Here +function last(array, callback){ + for(i in array){ + callback(array[array.length-1]); + } +} // Do not edit the code below. last(names, function(lastName){ @@ -66,7 +78,9 @@ last(names, function(lastName){ */ //Code Here - +function multiply(x, n, callback){ + callback(x*n); +} // 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 +99,11 @@ multiply(4, 3, function(answer){ */ //Code Here - +function contains(array, name, callback){ + for(i in array){ + array[i] == name ? callback(true) : callback(false); + } +} // Do not edit the code below. contains(names, 'Oscar', function(result){ if(result === true){ @@ -106,7 +124,10 @@ contains(names, 'Oscar', function(result){ */ //Code Here - +function uniq(array, callback){ + var thisArr = array.filter((item, index) => array.indexOf(item) === index); + callback(thisArr); +} // 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 +144,11 @@ uniq(names, function(uniqArr){ */ //Code Here - +function each(names, callback){ + for(var i = 0; i