-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat: All iterations for lab functions and arrays js #3848
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//OBJETOS | ||
|
||
const message = { | ||
from: '666666666', | ||
to: '6666555566' | ||
|
||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,41 +1,112 @@ | ||||||||||||||||||||||||||||||||||||
// Iteration #1: Find the maximum | ||||||||||||||||||||||||||||||||||||
function maxOfTwoNumbers() {} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
function maxOfTwoNumbers(num1, num2) { | ||||||||||||||||||||||||||||||||||||
let bigNumber; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if (num1 > num2) { | ||||||||||||||||||||||||||||||||||||
bigNumber = num1; | ||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||
bigNumber = num2; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
return bigNumber; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Iteration #2: Find longest word | ||||||||||||||||||||||||||||||||||||
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
function findLongestWord() {} | ||||||||||||||||||||||||||||||||||||
function findLongestWord(words) { | ||||||||||||||||||||||||||||||||||||
if (words.length === 0) { | ||||||||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if (words.length === 1) { | ||||||||||||||||||||||||||||||||||||
return words[0] | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
let longestWord = ''; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
for (let i = 0; i < words.length; i++) { | ||||||||||||||||||||||||||||||||||||
const findWord = words[i]; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if (findWord.length > longestWord.length || longestWord === '') { | ||||||||||||||||||||||||||||||||||||
longestWord = findWord; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
return longestWord; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Iteration #3: Calculate the sum | ||||||||||||||||||||||||||||||||||||
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
function sumNumbers() {} | ||||||||||||||||||||||||||||||||||||
function sumNumbers(numbers) { | ||||||||||||||||||||||||||||||||||||
if (numbers.length === 0) { | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Esto que te he puesto nada me he equivocado, seria para la funcion sum, no para sumNumbers, para sumNumbers estaba genial, pero si lo piensas bien, sum y sumNumbers son iguales, solo que sum tiene vitaminas jejeje |
||||||||||||||||||||||||||||||||||||
return 0; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
let sum = 0; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
for (let i = 0; i < numbers.length; i++) { | ||||||||||||||||||||||||||||||||||||
sum += numbers[i]; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
return sum; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Iteration #3.1 Bonus: | ||||||||||||||||||||||||||||||||||||
function sum() {} | ||||||||||||||||||||||||||||||||||||
//function sum() {} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Iteration #4: Calculate the average | ||||||||||||||||||||||||||||||||||||
// Level 1: Array of numbers | ||||||||||||||||||||||||||||||||||||
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
function averageNumbers() {} | ||||||||||||||||||||||||||||||||||||
function averageNumbers(numbers) { | ||||||||||||||||||||||||||||||||||||
if (numbers.length === 0) { | ||||||||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
let sum = 0; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
for (let i = 0; i < numbers.length; i++) { | ||||||||||||||||||||||||||||||||||||
sum += numbers[i]; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
const average = sum/ numbers.length; | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
soy un pijo.... |
||||||||||||||||||||||||||||||||||||
return average; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Level 2: Array of strings | ||||||||||||||||||||||||||||||||||||
const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace']; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
function averageWordLength() { } | ||||||||||||||||||||||||||||||||||||
function averageWordLength(words) { | ||||||||||||||||||||||||||||||||||||
if (words.length === 0) { | ||||||||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
let totalLenght = 0; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
for (let i = 0; i < words.length; i++) { | ||||||||||||||||||||||||||||||||||||
totalLenght += words[i].length; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
const averageLength = totalLenght / words.length; | ||||||||||||||||||||||||||||||||||||
return averageLength; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Bonus - Iteration #4.1 | ||||||||||||||||||||||||||||||||||||
function avg() {} | ||||||||||||||||||||||||||||||||||||
//function avg() {} | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
No te hace falta comentarlo, asi uno de los test no te falla jejeje |
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Iteration #5: Unique arrays | ||||||||||||||||||||||||||||||||||||
const wordsUnique = [ | ||||||||||||||||||||||||||||||||||||
|
@@ -52,14 +123,47 @@ const wordsUnique = [ | |||||||||||||||||||||||||||||||||||
'bring' | ||||||||||||||||||||||||||||||||||||
]; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
function uniquifyArray() {} | ||||||||||||||||||||||||||||||||||||
const uniqueArray = uniquifyArray(wordsUnique); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
function uniquifyArray(wordsDuplicate) { | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if (wordsDuplicate.length === 0) { | ||||||||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
for (let i = 0; i < wordsDuplicate.length; i++) { | ||||||||||||||||||||||||||||||||||||
const word = wordsDuplicate[i]; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
while (wordsDuplicate.indexOf(word, i + 1) !== -1) { | ||||||||||||||||||||||||||||||||||||
wordsDuplicate.splice(wordsDuplicate.indexOf(word, i + 1), 1); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
return wordsDuplicate; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Iteration #6: Find elements | ||||||||||||||||||||||||||||||||||||
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience']; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
function doesWordExist() {} | ||||||||||||||||||||||||||||||||||||
function doesWordExist(findElements, searchWord) { | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if (findElements.length === 0) { | ||||||||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
let i = 0 | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
while (i < findElements.length) { | ||||||||||||||||||||||||||||||||||||
if (findElements[i] === searchWord) { | ||||||||||||||||||||||||||||||||||||
return true; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
i++ | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
@@ -78,7 +182,18 @@ const wordsCount = [ | |||||||||||||||||||||||||||||||||||
'matter' | ||||||||||||||||||||||||||||||||||||
]; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
function howManyTimes() {} | ||||||||||||||||||||||||||||||||||||
const wordSearch = 'matter' | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
function howManyTimes(wordsCount, wordSearch) { | ||||||||||||||||||||||||||||||||||||
let count = 0; | ||||||||||||||||||||||||||||||||||||
for (let i = 0; i < wordsCount.length; i++) { | ||||||||||||||||||||||||||||||||||||
const wordFind = wordsCount[i]; | ||||||||||||||||||||||||||||||||||||
if (wordSearch === wordFind) { | ||||||||||||||||||||||||||||||||||||
count++ | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
return count; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Para que no te falle, el nombre de las funciones tiene que ser el que te venia por defecto si no falla los test de jasmine jejeje
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahora mismo el codigo que tienes implementado solo suma numeros, es decir si te llega un string, o un array, o un objeto, o un booleano los intentas sumar todos, y eso no deberia ser asi, tienes que especificarlos un poco, te pongo como lo haria yo vale? y me dices cualquier cosa y lo vemos vale??