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

Mia ftwd Alex Rojas#507

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
alexrojas wants to merge1 commit intoironhack-labs:masterfromalexrojas:master
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
13 changes: 8 additions & 5 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,9 +77,9 @@ Run the tests with Jasmine is super easy, you just have to open the `SpecRunner.

**Pass the tests**

You have to write your code on the `src/functions-and-arrays.js` file. Following the instructions, you should go step by step passing all the tests.
You have to write your code on the `src/functions-and-arrays.js` file. Following the instructions, you should go step by step passing all the tests.

Do not rush to go through all of them at once, take your time to read carefully about what the iteration is asking you, and solve the errors one by one.
Do not rush to go through all of them at once, take your time to read carefully about what the iteration is asking you, and solve the errors one by one.

When coding with tests, is super important to read and understand the errors we are having for each test, this way we will know what it expect from your code.

Expand All@@ -89,11 +89,11 @@ All our work will be located in the `functions-and-arrays.js` file, so that will

## Find the maximum

Define a function `maxOfTwoNumbers` that takes two numbers as arguments and returns the largest.
Define a function `maxOfTwoNumbers` that takes two numbers as arguments and returns the largest.

## Finding Longest Word

Write a function `findLongestWord` that takes an array of words and returns the longest one. If there are 2 with the same length, it should return the first occurrence.
Write a function `findLongestWord` that takes an array of words and returns the longest one. If there are 2 with the same length, it should return the first occurrence.

**Starter Code**

Expand DownExpand Up@@ -186,6 +186,9 @@ var words = [
'bring'
];




```

## Finding Elements
Expand DownExpand Up@@ -259,4 +262,4 @@ var matrix = [
[20,73,35,29,78,31,90,01,74,31,49,71,48,86,81,16,23,57,05,54],
[01,70,54,71,83,51,54,69,16,92,33,48,61,43,52,01,89,19,67,48],
];
```
```
152 changes: 152 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,16 @@
// Find the maximum

function maxOfTwoNumbers(firstNum, secondNum){
if(firstNum > secondNum){
return firstNum
} else if(secondNum > firstNum){
return secondNum
} else {
return firstNum
}

}

// Finding Longest Word
var words = [
'mystery',
Expand All@@ -11,14 +22,84 @@ var words = [
'crackpot'
];

// function findLongestWord(x){
// if(x = []){
// return undefined
// }else if(x.length > 0){
// var largest = x.reduce((a, b) => a.length >= b.length ? a : b)
// console.log(largest);
// } else{
// return x
// }
//
// }

// function findLongestWord(array){
//
//
// }

function findLongestWord(array){
var x = []
x.push(array[0])

if(array.length === 1){
return x[0]
}else {
for(i = 1; i< array.length; i++){
if(array[i].length > x[0].length){
x = array[i]
return x
} else if(array[i] === x[0]){
x = x[0]
}
}

}


}

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

// Calculating a Sum

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

function sumArray(array1){
array1 = array1.reduce(function(a, b){
return a + b
}, 0)
return array1
}


// Calculate the Average

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

function averageNumbers(x){
if(x.length === 0){
return undefined
}else{
var total = 0
for(i = 0; i < x.length; i++ ){
total += x[i]
}
return total / x.length
}

}


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


function averageWordLength(x){
var arrayCount = []
if(x.length === 0){
return undefined
}else if(x.length === 1){
for(i = 0; i<= x.length; i++){
return x[i].length
}
}else{
// var arrayCount = []
for(i = 0; i< x.length; i++){
arrayCount.push(x[i].length)
}
}
var total = 0
for(i = 0; i < arrayCount.length; i++ ){
total += arrayCount[i]
}
return total / x.length

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

// function uniquifyArray(array){
// if(array.length === 0){
// return undefined
// } else{
// var unique = array.filter((v, i, a) => a.indexOf(v) === i);
// return unique
// }
//
// }

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


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

function doesWordExist(array){
if(array.length === 0 ){
return false
}else{
for(let i = 0; i < array.length; i++){
if(array.indexOf(array[i]) === -1){
return false
}else if(array.indexOf(array[i]) >= 0){
return true
}
}
}
}
// Counting Repetion
var wordsCount = [
'machine',
Expand All@@ -74,6 +215,17 @@ var wordsCount = [
'disobedience',
'matter'
];

function howManyTimes(arr){
var counts = []
for(var i = 0; i < arr.length; i++ ){
var num = arr[i]
counts[num] = counts[num] ? counts[num] + 1 : 1
}


return counts
}
// Bonus Quest

var matrix = [
Expand Down
1 change: 0 additions & 1 deletionstarter-code/tests/FunctionsAndArraysSpec.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -243,4 +243,3 @@ describe('Counting Repetion - greatestProduct', function () {
expect(greatestProduct(matrix)).toBe(16);
});
});


[8]ページ先頭

©2009-2025 Movatter.jp