Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[WEB-PT2017] [RAFA LÓPEZ] #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 89 additions & 10 deletions 99 starter-code/functions-and-arrays.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
// Find the maximum
function maxOfTwoNumbers (first, second) {

function maxOfTwoNumbers (first, second) {
if (first > second) {
return first;
}
return second;
}

var largest = maxOfTwoNumbers(2, 6);
var largest = maxOfTwoNumbers(2, 7);
console.log(largest);


// Finding Longest Word
function findLongestWord (words) {


var palabra = "";

function findLongestWord (words) {
var resultado = 0;
for (i = 0; i < words.length; i++) {
if (words[i].length > resultado) {
resultado = words[i].length;
palabra = words[i]}
} return palabra;
}

var words = [
Expand All @@ -20,32 +34,71 @@ var words = [
"orchard",
"crackpot"
];


var longest = findLongestWord(words);
console.log(longest);



// Calculating a Sum
function sumArray (array) {


function sumArray (array) {
for(i = 0; i < numbers.length; i++) {
if (numbers[i] !== 0) {arraySumado += numbers[i]}
} return arraySumado;
}

var arraySumado = 0;
var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
var total = sumArray(numbers);
console.log(total);




// Calculate the Average
function averageNumbers (array) {


function averageNumbers (array) {
for(i=0; i < numbers.length; i++) {
if (numbers[i] !== 0) {resultadoParaMedia += numbers[i]}
} return resultadoParaMedia;
}

var resultadoParaMedia = 0;
var numbers = [2, 6, 9, 10, 7, 4, 1, 9];
var average = averageNumbers(numbers);


var average = averageNumbers(numbers) / numbers.length;
console.log(average);



// Array of Strings



function averageWordLength (array) {
for (i = 0; i < words.length; i++) {
if (words[i].length !== 0) {letrasArray += words[i].length}
} return letrasArray;
}


var letrasArray = 0;

var words = [];
function averageWordLength (array) {
for (i = 0; i < words.length; i++) {
if (words[i].length !== 0) {letrasArray += words[i].length}
} return letrasArray;
}


var letrasArray = 0;

var words = [
"seat",
"correspond",
Expand All @@ -58,14 +111,25 @@ var words = [
"fuel",
"palace"
];
var averageLength = averageWordLength(words);

var averageLength = averageWordLength(words)/words.length;
console.log(averageLength);

var averageLength = averageWordLength(words)/words.length;
console.log(averageLength);


// Unique Arrays
function uniquifyArray (array) {

function uniquifyArray (array) {
for (i = 0; i < words.length; i++){
if (uniqueArray.indexOf(words[i]) == -1) {
uniqueArray.push(words[i]);
}
} return uniqueArray;
}


var words = [
"crab",
"poison",
Expand All @@ -79,12 +143,19 @@ var words = [
"simple",
"bring"
];

var uniqueArray = [];
var uniqued = uniquifyArray(words);
console.log(uniqued);


// Finding Elements
function doesWordExist (wordsArray, word) {

for (i = 0; i < wordsArray.length; i++) {
if (word == wordsArray[i]) {
return true }
}
return false;
}

var words = [
Expand All @@ -105,8 +176,13 @@ var hasDog = doesWordExist(words, "dog");
console.log(hasDog);

// Counting Repetion
function howManyTimes (words, word) {

function howManyTimes (words, word) {
var resultado = 0;
for(i = 0; i < words.length; i++){
if (word == words[i]) {resultado +=1}
}
return resultado;
}

var words = [
Expand All @@ -129,7 +205,10 @@ console.log(howManyMatter);
var howManyDog = howManyTimes(words, "dog");
console.log(howManyDog);


// Bonus Quest

// Todavía no esta hecho.
function greatestProduct (matrix) {

}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.