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

updated- VITFED010#80

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

Open
Adhirohah232 wants to merge2 commits intoprograd-org:master
base:master
Choose a base branch
Loading
fromAdhirohah232:master
Open
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
1 change: 1 addition & 0 deletions_config.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
theme:jekyll-theme-slate
115 changes: 107 additions & 8 deletionssrc/functions-and-arrays.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,81 @@
// Progression #1: Greatest of the two numbers

function greatestOfTwoNumbers(a,b){
return a>b?a:b;
}
// Progression #2: The lengthy word
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];

var words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
function findScaryWord(words){
if(words.length===0)
return null;
var j=0;
for(var i=1;i<words.length;i++){

words[i-1].length>=words[i].length?(words[i]=words[i-1]):j++;
}
return words[words.length-1];
}
// Progression #3: Net Price
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];

function netPrice(arr){
if(arr.length===0)
return 0;
return arr.reduce((a,b)=>a+b)
}
function add(arr){
var total=0;
if(arr.length===0)
return 0;
for(var i=0;i<arr.length;i++){
if(typeof(arr[i])==='string'){
total+=arr[i].length;
}
else if(typeof(arr[i])==='boolean'){
total+=arr[i]===true?1:0;
}
else if(typeof(arr[i])==='number'){
total+=arr[i];
}
else{
throw Error("Unsupported data type sir or ma'am");}
}
return total;
}
// Progression #4: Calculate the average

// Progression 4.1: Array of numbers
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];

function midPointOfLevels(arr){
if(arr.length===0)
return null;
return arr.reduce((a,b)=>a+b)/arr.length
}
// Progression 4.2: Array of strings
const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace'];

function averageWordLength(arr){
var total=0;
if(arr.length===0)
return null;
for(var i=0;i<arr.length;i++){
total+=arr[i].length;}
return total/arr.length;
}
function avg(arr){
var total=0;
if(arr.length===0)
return null;
for(var i=0;i<arr.length;i++){
if(typeof(arr[i])==='string'){
total+=arr[i].length;
}
else if(typeof(arr[i])==='boolean'){
total+=arr[i]===true?1:0;
}
else if(typeof(arr[i])==='number'){
total+=arr[i];
}
}
return Number((total/arr.length).toFixed(2));
}
// Progression #5: Unique arrays
const wordsUnique = [
'bread',
Expand All@@ -28,10 +91,23 @@ const wordsUnique = [
'egg',
'flour'
];

function uniqueArray(s){
if(s.length===0)
return null;
return [...new Set(s)];
}
// Progression #6: Find elements
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];

function searchElement(arr,serele){
if(arr.length===0)
return null;
for(let i=0;i<arr.length;i++){
if(arr[i]===serele)
return true;
}

}
// Progression #7: Count repetition
const wordsCount = [
'machine',
Expand All@@ -46,7 +122,16 @@ const wordsCount = [
'disobedience',
'matter'
];

function howManyTimesElementRepeated(s,repele){
var count=0;
if(s.length===0)
return 0;
for(var i=0;i<s.length;i++)
{if(s[i]===repele)
count+=1;
}
return count;
}
// Progression #8: Bonus

const matrix = [
Expand All@@ -61,3 +146,17 @@ const matrix = [
[24, 55, 58, 05, 66, 73, 99, 26, 97, 17],
[21, 36, 23, 09, 75, 00, 76, 44, 20, 45]
];
function maximumProduct(matrix){
pro=0;
for(var i=0;i<matrix.length;i++){
for(var j=0;j<matrix[i].length;j++){
if(matrix[i][j]==1){
pro=1;
}
else{
pro=0;
}
}
}
return pro;
}

[8]ページ先頭

©2009-2025 Movatter.jp