Skip to content
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

Added FizzBizz.js #725

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
23 changes: 23 additions & 0 deletions Javascript/checkGoodPairsInArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
checkGoodPairsInArray.js

Added checkGoodPairsInArray.js

// Given an array A and a integer B. A pair(i,j) in the array is a good pair if i!=j and (A[i]+A[j]==B). Check if any good pair exist or not.

function checkGoodPairsInArray(A, B){
let arrASize = A.length;
// For every number traverse all numbers right to it
for(let i = 0; i <(arrASize - 1); i++){
for(let j = (i + 1); j <(arrASize); j++){
if((A[i] + A[j]) == B){
return 1;
}
}
}
return 0;
}

let A = [1,2,3,4];
let B = 7;
let out = checkGoodPairsInArray(A,B);
console.log(out);
21 changes: 21 additions & 0 deletions Javascript/fizzBuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Given a positive integer A, return an array of strings with all the integers from 1 to N. But for multiples of 3 the array should have “Fizz” instead of the number. For the multiples of 5, the array should have “Buzz” instead of the number. For numbers which are multiple of 3 and 5 both, the array should have "FizzBuzz" instead of the number.
function fizzBuzz(A){
let out = [];
for(let num = 1; num <= A; num++){
let remainderBy5 = num % 5;
let remainderBy3 = num % 3;
if((!remainderBy5) && (!remainderBy3) ){
out.push( "FizzBuzz");
}else if(!remainderBy3){
out.push( "Fizz");
}else if(!remainderBy5){
out.push( "Buzz");
}else{
out.push(num);
}
}
return out;
}

let A = 5;
console.log(fizzBuzz(A));
21 changes: 21 additions & 0 deletions fizzBuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Given a positive integer A, return an array of strings with all the integers from 1 to N. But for multiples of 3 the array should have “Fizz” instead of the number. For the multiples of 5, the array should have “Buzz” instead of the number. For numbers which are multiple of 3 and 5 both, the array should have "FizzBuzz" instead of the number.
function fizzBuzz(A){
let out = [];
for(let num = 1; num <= A; num++){
let remainderBy5 = num % 5;
let remainderBy3 = num % 3;
if((!remainderBy5) && (!remainderBy3) ){
out.push( "FizzBuzz");
}else if(!remainderBy3){
out.push( "Fizz");
}else if(!remainderBy5){
out.push( "Buzz");
}else{
out.push(num);
}
}
return out;
}

let A = 5;
console.log(fizzBuzz(A));