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

DE Mex Alex & Enrique#781

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
Show file tree
Hide file tree
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
Binary file added.DS_Store
View file
Open in desktop
Binary file not shown.
122 changes: 122 additions & 0 deletionsstarter-code/src/functions-and-arrays.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
// Find the maximum

function maxOfTwoNumbers (x, y){
if(x > y) return x
return y
}
// Finding Longest Word
var words = [
'mystery',
Expand All@@ -11,14 +15,63 @@ var words = [
'crackpot'
];

function findLongestWord(array){

let counter = 0;
let longestWord = "";


if(array.length == 0){
return undefined
}else {

for (let i = 0; i < array.length; i++){
if(array[i].length > counter){
counter = array[i].length
longestWord=array[i]
}
}

return longestWord
}
}

// Calculating a Sum

var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];


function sumArray(array){
let sum = 0;

for (let i = 0; i < array.length; i++){
sum = sum + array[i];
}

return sum
}

// Calculate the Average

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

function averageNumbers(x){
if(x.length == 0){
return undefined
}else {
let sum = 0;


for (let i = 0; i < x.length; i++){
sum += x[i]
}

let average = sum/x.length

return average

}}

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

function averageWordLength(array){
let sum = 0
if(array.length == 0){
return undefined
} else{
for (var i=0;i<array.length;i++){
sum += array[i].length
}

let average = sum/array.length

return(average)
}

}

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

function uniquifyArray(array){

let newArray = []
let word = ""




if(array.length == 0){
return undefined
}else {
for (i in array){
word = array[i]
if(i == array.indexOf(word)){
newArray.push(word)
}
}
}
return newArray


}



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

function doesWordExist(array,word){

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

return false
}


// Counting Repetion
var wordsCount = [
'machine',
Expand All@@ -74,6 +179,23 @@ var wordsCount = [
'disobedience',
'matter'
];

function howManyTimes(array,word){

if(array.length == 0){
return false
} else {
let counter = 0;

for (let i = 0; i < array.length; i++){
if(word == array[i]){
counter += 1}
}

return counter
}

}
// Bonus Quest

var matrix = [
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp