Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Lab Pedro Aviles Jesus Alonso y Ricardo Hernandez#784

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
unrhs wants to merge1 commit intoironhack-labs:masterfromunrhs:master
Closed
Changes fromall 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
212 changes: 211 additions & 1 deletionstarter-code/src/functions-and-arrays.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
// Find the maximum
function maxOfTwoNumbers (a,b){
if(a>b){
return a
} else { return b
}
}

// Finding Longest Word
var words = [
Expand All@@ -9,16 +15,80 @@ var words = [
'pearl',
'orchard',
'crackpot'
];
]
function
findLongestWord(words){

var maxLong1 = 0

var indicePal = 0

if(words.length === 0){

return undefined;

}

words.forEach(function(word,index)
{

var long1 = word.length;

if(long1 > maxLong1){

maxLong1=long1;

indicePal=index;

}

});


return words[indicePal];

}



// Calculating a Sum

var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
function sumArray(numbers) {

return numbers.reduce(function(a,b) {
return a + b
},0); // the use of 0 let us reduce the mistake when the array is empty
}


// Calculate the Average

var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];


function
averageNumbers(arrayNumbers){
var sumNumbers = 0;

if (arrayNumbers.length === 0){
return
undefined;
}

arrayNumbers.forEach(
function(number) {

sumNumbers += number;
});

return sumNumbers / arrayNumbers.length;
}





// Array of Strings
var wordsArr = [
'seat',
Expand All@@ -33,6 +103,41 @@ var wordsArr = [
'palace'
];

function averageWordLength (wordsArr){

// cre una vriable que es tamaño de wordArrs

var totaldelar = wordsArr.length

//totla de las suma de las palabras comienza en 0

var totalp = 0

//

if(totaldelar===0){

return undefined

}else{wordsArr.forEach(function(word){

//

totalp=word.length + totalp})

//

var
promedio= totalp/totaldelar

// regreso el promedio

return promedio}

}



// Unique Arrays
var wordsUnique = [
'crab',
Expand All@@ -48,6 +153,67 @@ var wordsUnique = [
'bring'
];

function uniquifyArray(arrayUnify){

var continueSearch = true;

var i = 0;



if (arrayUnify.length === 0){

return undefined;

}



do {

// Obtain word to search

var wordSearch = arrayUnify[i];



// end of array

if (wordSearch === undefined){

continueSearch = false;

} else {
//search word to delete duplicate

// Search word in array just after index

var wordIndex = arrayUnify.indexOf(wordSearch,i+1);



// found?

if (wordIndex >= 0){

//delete word

arrayUnify.splice(wordIndex,1);

} else {
//not found, increment index to search next word

i++;

}}

} while (continueSearch);

return arrayUnify;
}



// Finding Elements
var wordsFind = [
'machine',
Expand All@@ -60,6 +226,27 @@ var wordsFind = [
'disobedience'
];

function doesWordExist(wordsFind, word) {

for (i=0; i<wordsFind.length;
i++) {

if (word.includes(wordsFind[i]))

{ return true }

else { continue

}

}

return false

}



// Counting Repetion
var wordsCount = [
'machine',
Expand All@@ -74,8 +261,31 @@ var wordsCount = [
'disobedience',
'matter'
];
function howManyTimes(arrayWords, wordToSearch){

var numberWords = 0;

var nextWord = arrayWords.indexOf(wordToSearch);



if(arrayWords.length === 0){

return false;}

while(nextWord >= 0){

numberWords++;

nextWord = arrayWords.indexOf(wordToSearch,nextWord+1);

}
return numberWords;
}

// Bonus Quest


var matrix = [
[8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8],
[49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 4, 56, 62, 0],
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp