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

MEXPT-César Hernández#360

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
Cestarck wants to merge2 commits intoironhack-labs:masterfromCestarck: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
14 changes: 14 additions & 0 deletionsstarter-code/.vscode/launch.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
{
// 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": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/src/functions-and-arrays.js"
}
]
}
124 changes: 115 additions & 9 deletionsstarter-code/src/functions-and-arrays.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,53 @@
// Find the maximum
function maxOfTwoNumbers(number1,number2){
if(number1>number2){
return number1;
}else{
return number2;
}
}

// Finding Longest Word
var words = [
'mystery',
'brother',
'aviator',
'crocodile',
'pearl',
'orchard',
'crackpot'
];

function findLongestWord(words){
let longest="";
for(let i=0;i<words.length; i++){
if(words[0].length<words[i].length){
words[0]=words[i];

}
}
return words[0];
}
console.log(findLongestWord(words));
// Calculating a Sum

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

function sumArray(numbers){
let sum=0;
for(let i=0;i<numbers.length;i++){
sum+=numbers[i];
}
return sum;
}

// Calculate the Average

var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];
function averageNumbers(numbers){
let sum=0;
for(let i=0;i<numbers.length;i++){
sum+=numbers[i];
}
if(numbers.length==0){
return undefined;

}else{
return sum/numbers.length;
}

}
// Array of Strings
var wordsArr = [
'seat',
Expand All@@ -32,6 +61,18 @@ var wordsArr = [
'fuel',
'palace'
];
function averageWordLength(words){
let sum=0;
for(let i=0;i<words.length;i++){
sum+=words[i].length;
}
if(words.length==0){
return undefined;
}else{
return sum/words.length;
}
}


// Unique Arrays
var wordsUnique = [
Expand All@@ -48,6 +89,28 @@ var wordsUnique = [
'bring'
];



function uniquifyArray(words){
var magic=[];
for(let i=0;i<words.length;i++){
if(words.indexOf(words[i],i+1)>=0){
console.log((words.indexOf(words[i],i+1)));
words.splice((words.indexOf(words[i],i+1)),1);
i--;
}else{
magic.push(words[i]);
}
}

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


// Finding Elements
var wordsFind = [
'machine',
Expand All@@ -59,6 +122,17 @@ var wordsFind = [
'truth',
'disobedience'
];
function doesWordExist(array,word){
let exists=false;
for(let i=0;i<array.length;i++){
if(word===array[i]){
exists=true;
break;
}
}

return exists;
}

// Counting Repetion
var wordsCount = [
Expand All@@ -74,6 +148,24 @@ var wordsCount = [
'disobedience',
'matter'
];
function howManyTimes(array,word){
let count=0;
if(array.length==0){
return false;
}else{
let indice=array.indexOf(word);
console.log(indice);
while(indice>=0){
count++;
indice=array.indexOf(word,indice+1);
console.log(indice);
}
return count;
}

}


// Bonus Quest

var matrix = [
Expand All@@ -98,3 +190,17 @@ var matrix = [
[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]
];
function greatestProduct(matriz){
var producto=0;
for(i=0;i<matriz.length-3;i++){
for(j=0;j<matriz.length-3;j++){
if((matriz[i][j]*matriz[i+1][j]*matriz[i+2][j]*matriz[i+3][j])<producto){
producto=matriz[i][j]*matriz[i+1][j]*matriz[i+2][j]*matriz[i+3][j];
}
if((matriz[i][j]*matriz[i][j+1]*matriz[i][j+2]*matriz[i][j+3])>producto){
producto=matriz[i][j]*matriz[i][j+1]*matriz[i][j+2]*matriz[i][j+3];
}
}
}
return producto;
}

[8]ページ先頭

©2009-2025 Movatter.jp