Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fourth commit, iteration six
  • Loading branch information
Y-VW committed Feb 18, 2020
commit 93aebf421b2cc9b6a875cebfe159b35290dcf8d6
40 changes: 40 additions & 0 deletions starter-code/src/functions-and-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ function averageNumbers(array){
// Level 2: Array of strings
const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace'];

function averageWordLength (array){
if (array.length === 0){
return null;
} else {
average = array.join('').length / array.length
return average;
}
}

// function avg (array){
// if (array.length === 0){
// return null;
// } else {
// }
// }

// Iteration #5: Unique arrays
const wordsUnique = [
'crab',
Expand All @@ -74,9 +90,33 @@ const wordsUnique = [
'bring'
];


function uniquifyArray (array){
if (array.length === 0){
return null;
} else {
return array.filter((a,b) => array.indexOf(a) === b)
}
}

console.log(uniquifyArray(words));

// Iteration #6: Find elements
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];


function doesWordExist (array, word){
if (array.length === 0){
return null;
} else {
if (array.includes(word) === true){
return true;
} else {
return false;
}
}
}

// Iteration #7: Count repetition
const wordsCount = [
'machine',
Expand Down