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

BCN PT - Nuria Casas Crous#374

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
sasrous wants to merge1 commit intoironhack-labs:masterfromsasrous: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
84 changes: 83 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,14 @@
// Find the maximum
function maxOfTwoNumbers (a, b){
if (a > b){
return a;
}
else {
return b;
}
}



// Finding Longest Word
var words = [
Expand All@@ -11,13 +21,44 @@ var words = [
'crackpot'
];

function findLongestWord (arr) {
var longest = ''
if (arr.length === 0){
return
}
for (i=0; i < arr.length; i++) {
if (arr[i].length > longest.length) {
longest = arr[i];
}
}
return longest;
}



// Calculating a Sum

var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
function sumArray(arr){
if (arr.length === 0){
return sum = 0;}
var sum = 0;
for (i=0; i < arr.length; i++){
sum += arr[i];
}
return sum;}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Recuerda tabular el código


// Calculate the Average

var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];
function averageNumbers (arr){
if (arr.length === 0){
return}
var average = sumArray(arr)/arr.length;
return average;
}



// Array of Strings
var wordsArr = [
Expand All@@ -32,6 +73,16 @@ var wordsArr = [
'fuel',
'palace'
];
function averageWordLength(arr){
if (arr.length === 0){
return}
var wordLength = []
for (i=0; i < arr.length; i++) {
wordLength.push(arr[i].length)
}
return averageNumbers(wordLength);
}
console.log(averageWordLength(wordsArr));

// Unique Arrays
var wordsUnique = [
Expand All@@ -47,6 +98,17 @@ var wordsUnique = [
'simple',
'bring'
];
function uniquifyArray(arr){
if (arr.length === 0){
return}
var newArray = [];
for (i=0; i < arr.length; i++) {
if (newArray.indexOf(arr[i]) === -1){
newArray.push(arr[i])}
}
return newArray;
}


// Finding Elements
var wordsFind = [
Expand All@@ -59,7 +121,15 @@ var wordsFind = [
'truth',
'disobedience'
];

function doesWordExist (arr, word) {
if (arr.length === 0){
return false;}
for (i=0; i < arr.length ; i++) {
if (arr[i] === word){
return true;}
}
return false;
}
// Counting Repetion
var wordsCount = [
'machine',
Expand All@@ -74,6 +144,18 @@ var wordsCount = [
'disobedience',
'matter'
];
function howManyTimes(arr,word){
var wordCount = [];
if (arr.length === 0){
return false;}
for (i=0; i < arr.length ; i++) {
if (arr[i] === word){
wordCount.push(arr[i]);
;}
}
return wordCount.length;

}
// Bonus Quest

var matrix = [
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp