Skip to content

JavaScript #3

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 5 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
99 changes: 99 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,102 @@

Please fork add your solution then open pull request.
Good luck!



1______________

var arr=[];
var n=0;;
var m=0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't use global variables, move n and m inside of function's body


function sorT(arr){

for(var i=0; i<arr.length;i++){
Copy link
Contributor

Choose a reason for hiding this comment

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

Use forEach instead of for


if( typeof(arr[i]) == 'number' )
Copy link
Contributor

Choose a reason for hiding this comment

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

Always use brackets after if / else

n++;

else if (typeof(arr[i]) == 'string')
m++;
}
return "Numbers :" + n + " " + "Strings :" + m;
}
console.log(sorT([1,"10","hi",9]));


2__________________________________________________

function longestW (str){

let word="";

var str=String(str);

var arr=Array(arr);

var arr= str.trim().split(" ");

for(var i=0;i<arr.length;i++){


if(word.length < arr[i].length)


word=arr[i];

}

return word;

}

console.log(longestW("London is a capital of The Great Britain"));

3_____________________________________________________

var arr=[];

var newarray=[];

function larger(arr,n){

for(var i=0; i< arr.length;i++){

if(arr[i]>n)

newarray.push(arr[i]);

}

return newarray;

}

console.log(larger([1,5,4,6,8,9,10],7));
4_________________________________________________________














5________________________________________________

var arr=[];

function rotate(arr,n){

return arr.splice(n,arr.length).concat(arr.splice(0,n));
}

console.log(rotate([1,2,3,4,5,6],2));