This file contains hidden or 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 arrayOfProducts(array) { | |
const resultArray = new Array(array.size) | |
const leftArray = new Array(array.size) | |
const rigthArray = new Array(array.size) | |
// Generate right array | |
let leftProduct = 1; | |
for (let i = 0; i < array.length; i++) { | |
leftArray[i] = leftProduct | |
leftProduct = leftProduct * array[i] |
This file contains hidden or 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 tournamentWinner(competitions, results) { | |
// Write your code here. | |
let maxWinnerCounter = Number.MIN_VALUE | |
let maxWinnerKey = "" | |
const resultsCounter = {}; | |
console.log("bacon", results); | |
for (let i = 0; i < results.length; i++) { | |
const winnerKey = results[i] ? competitions[i][0] : competitions[i][1] | |
console.log("winnerKey", winnerKey); | |
// store counter |
This file contains hidden or 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 sortedSquaredArray(array) { | |
// Write your code here. | |
const squareResult = new Array(array.length) | |
let leftPointer = 0 | |
let rightPointer = array.length - 1 | |
// The important part is to reverse the array | |
for (let i = rightPointer; i >= 0; i--) { | |
let leftValue = Math.abs(Math.pow(array[leftPointer], 2)) | |
let rightValue = Math.abs(Math.pow(array[rightPointer], 2)) | |
squareResult[i] = Math.max(leftValue, rightValue) |
This file contains hidden or 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
const person = { | |
name: "Juan", | |
lastName: "Ortiz", | |
} | |
const printName = function() { // Important this can't be arrow function | |
console.log(`${this.name} ${this.lastName}`); | |
} | |
const printPerson = printName.bind(person); |
This file contains hidden or 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 maxSubarraySum(arr, num) { | |
let maxSum = 0; | |
let tempSum = 0; | |
if (arr.length < num) { return null } | |
for (let i = 0; i < num; i++) { | |
maxSum += arr[i] | |
} | |
tempSum = maxSum; | |
for (let i = num; i < arr.length; i++) { | |
tempSum = tempSum - arrp[i - num] + arr[i]; |
This file contains hidden or 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 countUniqueValues(numbers){ | |
// add whatever parameters you deem necessary - good luck! | |
if (!numbers.length) return 0; | |
let left = 0; | |
let right = 1; | |
let counter = 1; | |
while (right < numbers.length) { | |
if (numbers[left] !== numbers[right]) { |
This file contains hidden or 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 sumZero(arr) { | |
let left = 0; | |
let right = aro.length -1; | |
while (left < right) { | |
let sum = arr[left] + arr[right]; | |
if (sum == 0) { | |
return [arr[left]], arr[right] | |
} else { | |
right—; | |
} else { |
This file contains hidden or 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 validAnagram(strA, strB){ | |
if (strA.length !== strB.length) return false; | |
const strAcounter = {}; | |
for (const char of strA) { | |
strAcounter[char] = (strAcounter[char] || 0) + 1; | |
} | |
const strBcounter = {}; | |
for (const char of strB) { | |
strBcounter[char] = (strBcounter[char] || 0) + 1; | |
} |
This file contains hidden or 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
class FrozenYoghurt { | |
constructor(flavor, price) { | |
this.flavor = flavor | |
this.price = price | |
} | |
orderPlaced() { | |
console.log(`The ${this.flavor} flavor will cost you ${this.price} dollars`); | |
} | |
} |
This file contains hidden or 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 Soda(name,type,price) { | |
this.name = name; | |
this.type = type; | |
this.price = price; | |
this.display = function(){ | |
console.log(`The ${this.type} ${this.name} costs ${this.price} dollars`) | |
} | |
} | |
function Chips(name,type,price) { |