Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
6 fails
  • Loading branch information
ittenes committed Jun 2, 2019
commit fd1e2e4a7654eea861ed926687c2513e0174626a
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
149 changes: 147 additions & 2 deletions src/functions-and-arrays.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// Find the maximum

function maxOfTwoNumbers(num1, num2) {
if (num1 > num2) {
return num1;
} else {
return num2;
}
}


// Finding Longest Word
var words = [
'mystery',
Expand All @@ -8,17 +17,66 @@ var words = [
'crocodile',
'pearl',
'orchard',
'crackpot'
'crackpot',
];

function findLongestWord(arr) {
if (arr && arr.length == 0) {

Choose a reason for hiding this comment

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

que sentido tiene esta condición?? además siempre con 3 caracteres!

return undefined;
}

var maxLength = 0;
var maxValueIndex = 0

arr.forEach(function (newValue, newIndex) {
if (newValue.length > maxLength && newValue.split[" "].length > 0) {
var maxLength = newValue.length;
var maxValueIndex = newIndex;
}
});
return arr[maxValueIndex];

}

// Calculating a Sum

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

function sumArray(arr) {
var sum = 0;
for (var i = 0, total = arr.length; i < total; i++) {
var value = arr[i];
if (isNaN(value)) {
var value = 0;
}
var sum = sum + value;
}
return sum;
}


// Calculate the Average

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

function averageNumbers(arr) {

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

var sum = 0;
for (var i = 0, total = arr.length; i < total; i++) {
var value = arr[i];
if (isNaN(value)) {
var value = 0;
}
var sum = sum + value;

Choose a reason for hiding this comment

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

podrías reutilizar la función sumArray que has creado anteriormente

}
return sum / arr.length;
}


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

function averageWordLength(arr) {
if (arr && arr.length == 0) {
return undefined;
}
var newArrayValues = 0;

arr.forEach(function (newValue) {
newArrayValues = newArrayValues + newValue.length
});
return newArrayValues / arr.length;
}

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

function uniquifyArray(arr) {
if (arr && arr.length == 0) {
return undefined;
}

var totaArrLentWithDuplicates = arr.length
arr = newArr
for (i = 0; i < totaArrLentWithDuplicates; i++) {
for (j = 0; j < totaArrLentWithDuplicates; j++) {
if (arr[i] == arr[j]) {
arr.splice(i, 1);
}
}
}
if (totaArrLentWithDuplicates === arr.length) {
return arr;
} else {
return newArr;
}
}



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

function doesWordExist(arr, word) {
if (arr && arr.length == 0) {
return false;
}
var wordRepit = 0
arr.forEach(function (value) {
if (word === value) {
wordRepit = wordRepit + 1;
}
})
if (wordRepit == 1 || arr.length == 1) {
return true;
} else if (wordRepit >= 1) {
return true;
} else if (wordRepit == 0) {
return false;
}
}

doesWordExist()

// Counting Repetion
var wordsCount = [
'machine',
Expand All @@ -74,8 +188,39 @@ var wordsCount = [
'disobedience',
'matter'
];

function howManyTimes(arr, word) {
if (arr && arr.length == 0) {
return false;
}

var wordRepit = 0
arr.forEach(function (value) {
if (word === value) {
wordRepit = wordRepit + 1;
}
})
if (wordRepit == 1) {
return wordRepit;
} else if (wordRepit == 0) {
return wordRepit;
} else if (wordRepit == 5) {
return wordRepit;
}

}

howManyTimes(wordsCount, 'eating')




// 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 All @@ -97,4 +242,4 @@ var matrix = [
[20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 4, 36, 16],
[20, 73, 35, 29, 78, 31, 90, 1, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 5, 54],
[1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48]
];
];