This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// isUniqueRepeated('aaaaa'); | |
// ➞ true // because the character `a` is the single character which is repeated over the length of the array. | |
// isUniqueRepeated('aaabba'); | |
// ➞ false // because there is not a single character which is repeated over the length of the array. | |
// isUniqueRepeated(''); | |
// ➞ true // for empty strings return true. | |
// isUniqueRepeated('abcdef'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// canShop([ | |
// { product: "Milk", quantity: 1, price: 1.50 }, | |
// { product: "Cereals", quantity: 1, price: 2.50 } | |
// ], 5) ➞ true // because we have sufficient amount to purchase all the grocery items. | |
// canShop([ | |
// { product: "Milk", quantity: 1, price: 1.50 }, | |
// { product: "Eggs", quantity: 12, price: 0.10 }, | |
// { product: "Bread", quantity: 2, price: 1.60 }, | |
// { product: "Cheese", quantity: 1, price: 4.50 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pairElements([1, 2, 3, 4, 5, 6, 7]) ➞ [[1, 7], [2, 6], [3, 5], [4, 4]] | |
// pairElements([1, 2, 3, 4, 5, 6]) ➞ [[1, 6], [2, 5], [3, 4]] | |
// pairElements([5, 9, 8, 1, 2]) ➞ [[5, 2], [9, 1], [8, 8]] | |
// pairElements([]) ➞ [] | |
var newArray = new Array(); | |
function pairElements(arr){ | |
if(arr.length%2 == 0){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// // Implement the function fizz which prints all the numbers from 1 to 100 but for every third number it prints `fizz` instead. | |
// /* For eg. it should print: | |
function fizz(){ | |
for(let i=1; i<=100 ;i++ ) | |
{ | |
if (i%3 == 0){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
hammer('magic' , maxwell(-2, -3), 'butter'); | |
maxwell(-2,-3) | |
rossy(-2); | |
return false; | |
return true; | |
hammer("magic",true,'butter') | |
rossy("magic") | |
return false; | |
return "magic" + "butter" -> magicbutter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// // Write a function which takes in the farm and returns total spots in the farm. For eg. | |
// let farm = [['W', 'C', 'C'], ['C', 'C', 'C'], ['W', 'W', 'C'], ['C', 'C', 'W']]; | |
// // // has 4 rows and each row has 3 spots so total number of spots would be 12. | |
// console.log(totalSpots(farm)); // should print 12 | |
// function totalSpots(farm){ | |
// return farm.length * farm[0].length; | |
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//3,,,,,,,,,,,,,,,,,,, | |
let farm3 = [['W', 'C', 'W'], ['C', 'W', 'C'], ['C', 'C', 'C'], ['C', 'C', 'W'], ['C', 'C', 'C']] | |
// has 4 water outlets | |
function waterOutlets(farm){ | |
let count = 0; | |
for(let i = 0; i < farm.length;i++){ | |
for(let j=0; j< farm[0].length;j++){ | |
if(farm[i][j] == 'W' ){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findBoomrangs(arr){ | |
let count = 0; | |
for(let i=0; i<arr.length-2;i++){ | |
if(arr[i] == arr[i+2]){ | |
count = count +1; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nBonacciRatio(n) { | |
function fib(x, tem = [0, 1, 1]) { | |
if (tem[x]) { | |
return tem[x]; | |
} | |
tem[x] = n * fib(x - 1, tem) + fib(x - 2, tem); | |
return tem[x]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let simplified = (num) => { | |
let final = []; | |
for (let i = 1; i < num; i++) { | |
for (let j = i + 1; j <= num; j++) { | |
if (gcd(j, i) === 1) { | |
final.push(`${i}/${j}`) | |
} | |
} | |
} |
OlderNewer