From 5d4ce16579d77471aab61ff01be78662945d8deb Mon Sep 17 00:00:00 2001 From: "B.Vamsi Krishna" Date: Sat, 30 Oct 2021 08:32:29 -0700 Subject: [PATCH 1/2] 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. --- checkGoodPairsInArray.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 checkGoodPairsInArray.js diff --git a/checkGoodPairsInArray.js b/checkGoodPairsInArray.js new file mode 100644 index 0000000..01ad53a --- /dev/null +++ b/checkGoodPairsInArray.js @@ -0,0 +1,19 @@ +// 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); \ No newline at end of file From 1a4ca481303b697db2c5fd06955f57545e7a2c10 Mon Sep 17 00:00:00 2001 From: "B.Vamsi Krishna" Date: Sat, 30 Oct 2021 09:01:19 -0700 Subject: [PATCH 2/2] Added FizzBuzz.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- 12.FizzBuzz/fizzBuzz.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 12.FizzBuzz/fizzBuzz.js diff --git a/12.FizzBuzz/fizzBuzz.js b/12.FizzBuzz/fizzBuzz.js new file mode 100644 index 0000000..3a9d1f4 --- /dev/null +++ b/12.FizzBuzz/fizzBuzz.js @@ -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)); \ No newline at end of file