All generations.

generate functionThu, 15 Jun 2023

function compareStatements(people) { You have put each of the suspects and their information into an object as follows: const person1 = { name: 'Alice', statements: [ 'I was in the location', 'Bob was in the place', 'Charlie was not in the spot, 'Daisy was in the zone', 'Ethan was not in the room', ], }; Your objective is to compare the statements, and if any contradict, you want to put them into a nested array as part of a sub array, appending their name to their statement as follows: [['Alice: I was in the location', 'Bob: Alice was not in the location']] and return that array. Use the .includes() method instead of the == operator. Use if statement to add the contradicting statements to a nested array.

const person1 = { name: 'Alice', statements: [ 'I was in the location', 'Bob was in the place', 'Charlie was not in the spot', 'Daisy was in the zone', 'Ethan was not in the room', ], }; const person2 = { name: 'Bob', statements: [ 'I was in the location', 'Alice was not in the location', 'Charlie was not in the spot', 'Daisy was in the zone', 'Ethan was not in the room', ], }; const person3 = { name: 'Charlie', statements: [ 'I was not in the location', 'Alice was in the location', 'Bob was in the place', 'Daisy was in the zone', 'Ethan was not in the room', ], }; const person4 = { name: 'Daisy', statements: [ 'I was in the location',

Javascript
View
generate functionWed, 21 Jun 2023

You are designing a video game version of one of the most well known board games, chess. To start, you have decided to build the programming necessary to have a working digital pawn on your 8x8 chessboard. function findPawn(board) { Take a few chessboard arrays that have been created, check to see if you can move the pawn up one space, capture another pawn if possible, and promote the pawn to a Queen if it reaches the other side. You will not have to program for the "En Passant" maneuver for this exercise. In the array, spaces are represented by ' ', while any pawns are represented by 'p'. Queens are represented by 'Q'. should move the pawn one space should promote the pawn to a queen if it reaches the other side should attack another pawn if it is in the correct position

let board = [ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], ['p', ' ', ' ', ' ', ' ', ' ', ' ', ' '], ]; function findPawn(board) { for(let i = 0; i < board.length; i++){ for(let j = 0; j < board[i].length; j++){ if(board[i][j] === 'p'){ return [i, j] } } } } function movePawn(board

Javascript
View
generate functionWed, 21 Jun 2023

You are designing a video game version of one of the most well known board games, chess. To start, you have decided to build the programming necessary to have a working digital pawn on your 8x8 chessboard. function findPawn(board) { Take a few chessboard arrays that have been created, check to see if you can move the pawn up one space, capture another pawn if possible, and promote the pawn to a Queen if it reaches the other side. You will not have to program for the "En Passant" maneuver for this exercise. In the array, spaces are represented by ' ', while any pawns are represented by 'p'. Queens are represented by 'Q'. As an example, [ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', 'p', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] ]; should look like this to your computer when you are done: [ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', 'p', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] ];

function findPawn(board) { var pawn = null var newBoard = board for(var i = 0; i < board.length; i++) { for(var j = 0; j < board.length; j++) { if(board[i][j] === 'p') { pawn = [i,j] } } } if(board[pawn[0]-1][pawn[1]] === 'p') { newBoard[pawn[0]-1][pawn[1]] = ' ' } if(board[pawn[0]-1][pawn[1]] === ' ') { newBoard[pawn[0]-1][pawn[1]] = 'p' newBoard[pawn[0]][pawn[1]] = ' ' } if(pawn[0] === 7) { newBoard[pawn[0]][pawn[1]] = 'Q' } return newBoard }

Javascript
View
generate functionTue, 06 Jun 2023

Uh-oh, you've been given a nice opportunity to make some money... from the devil! It's quite simple. In a box of 25 drawers, there is a gold coin among them. all you have to do is find the coin, or else you lose your soul! Being a sporting person, the devil has 'graciously' allowed you to use your programming skills to find the gold coin. You have only one chance to open a drawer, so better put those programming skills to use! Map the object Find this object: {name: 'gold coin'} in a 2-dimensional array of objects provided to your function, findGoldCoin.

var drawers = [ [{name: 'one'}, {name: 'two'}, {name: 'three'}, {name: 'four'}], [{name: 'five'}, {name: 'six'}, {name: 'seven'}, {name: 'eight'}], [{name: 'nine'}, {name: 'ten'}, {name: 'eleven'}, {name: 'gold coin'}], [{name: 'thirteen'}, {name: 'fourteen'}, {name: 'fifteen'}, {name: 'sixteen'}] ]; function findGoldCoin(drawers){ for (var i = 0; i < drawers.length; i++) { for (var j = 0; j < drawers[i].length; j++) { if (drawers[i][j].name === 'gold coin') { return {x: i, y: j}; } } } } findGoldCoin(drawers);

Javascript
View
generate functionThu, 15 Jun 2023

Create JavaScript for digital clock function

function getTime() { let currentTime = new Date(); let hours = currentTime.getHours(); let minutes = currentTime.getMinutes(); let seconds = currentTime.getSeconds(); let period = "AM"; if (hours > 12) { hours -= 12; period = "PM"; } else if (hours === 0) { hours = 12; } if (seconds < 10) { seconds = "0" + seconds; } if (minutes < 10) { minutes = "0" + minutes; } let clockTime = hours + ":" + minutes + ":" + seconds + period; let clock = document.getElementById("clock"); clock.innerText = clockTime; }

Javascript
View
generate functionThu, 15 Jun 2023

There is a secret string which is unknown to you. Given a collection of random triplets from the string, recover the original string. A triplet here is defined as a sequence of three letters such that each letter occurs somewhere before the next in the given string. "whi" is a triplet for the string "whatisup". As a simplification, you may assume that no letter occurs more than once in the secret string. You can assume nothing about the triplets given to you other than that they are valid triplets and that they contain sufficient information to deduce the original string. In particular, this means that the secret string will never contain letters that do not occur in one of the triplets given to you.

function recoverSecret(triplets) { // ... }

Javascript
View
generate functionTue, 20 Jun 2023

Detective, we have a situation on our hands! The madman we've been hunting down got painted into a corner so he's holed up in the abandoned building that was scheduled to be torn down, with 4 innocent people as hostages. We still don't know who he is but we know he isMad. For each room, we want you to go through, see if anyone is there, and rescue them. But, we think the madman is hiding as one of the hostages. If you find him, don't bring him with you or he'll escape! You're the only one who can tell which one is the madman so we need you to find him. Return an array of the 4 hostages so we can have them accounted for, and then we'll sweep the building with the rest of the police so he can't possibly escape! You have a lot of rooms within rooms to search, so get cracking! const evilMaze = (maze) => { Do not use strings

function evilMaze(maze){ const result = []; for(let i = 0; i < maze.length; i++){ for(let j = 0; j < maze[i].length; j++){ if(typeof maze[i][j] === 'object'){ for(let k = 0; k < maze[i][j].length; k++){ if(maze[i][j][k] === 'madman'){ maze[i][j][k] = null; } else{ result.push(maze[i][j][k]) } } } else if(maze[i][j] === 'madman'){ maze[i][j] = null; } else{ result.push(maze[i][j]) } } } return result; }

Javascript
View
generate functionMon, 12 Jun 2023

You will be given an array of 5 named objects, "wet clothes", "jelly beans", "cement mix", "rocks", and "dirty laundry". Your boss has an array of tumblers, a dryer(), a flavorer(), a mixer(), a tumbler(), and a washer(). Your job is to take each object and using JavaScript, programatically tell the automated robotics system which tumbler to put each object in by passing the correct object as an argument to that tumbler's function given to you, the function will modify the object and then return the modified object. Your job is to return an array with the modified objects. Afterwards, as part of the challenge, you can explain your thought and coding process to the boss. function tumbler(items, functions) {

return items.map(function(item, index) { return functions[index](item); }); } function dryer(wetClothes) { return wetClothes + ' are dry'; } function flavorer(jellyBeans) { return jellyBeans + ' are sweet'; } function mixer(cementMix) { return cementMix + ' is mixed'; } function tumbler(rocks) { return rocks + ' are tumbled'; } function washer(dirtyLaundry) { return dirtyLaundry + ' are clean'; } var items = ['wet clothes', 'jelly beans', 'cement mix', 'rocks', 'dirty laundry']; var functions = [dryer, flavorer, mixer, tumbler, washer]; tumbler(items, functions); // Output: [ 'wet clothes are dry', // 'jelly beans are sweet', // 'cement mix is mixed', // 'rocks are tumbled', //

Javascript
View
generate functionWed, 21 Jun 2023

You are designing a video game version of one of the most well known board games, chess. To start, you have decided to build the programming necessary to have a working digital pawn on your 8x8 chessboard. Take a few chessboard arrays that have been created, check to see if you can move the pawn up one space, capture another pawn if possible, and promote the pawn to a Queen if it reaches the other side. You will not have to program for the "En Passant" maneuver for this exercise. In the array, spaces are represented by ' ', while any pawns are represented by 'p'. Queens are represented by 'Q'. As an example, [ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', 'p', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] ]; should look like this to your computer when you are done: [ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', 'p', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] ];

// Your code here function chessBoard(board) { for(var i = 0; i < board.length; i++){ for(var j = 0; j < board[i].length; j++){ if(board[i][j] == 'p'){ board[i][j] = ' '; board[i-1][j] = 'p'; } } } return board; } // Tests Test.describe("Basic Tests", function() { var board = [ [' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ','p',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' '], [' ','

Javascript
View
generate functionThu, 15 Jun 2023

In JavaScript Given an array X of positive integers, its elements are to be transformed by running the following operation on them as many times as required: if X[i] > X[j] then X[i] = X[i] - X[j] When no more transformations are possible, return its sum ("smallest possible sum"). For instance, the successive transformation of the elements of input X = [6, 9, 21] is detailed below: X_1 = [6, 9, 12] # -> X_1[2] = X[2] - X[1] = 21 - 9 X_2 = [6, 9, 6] # -> X_2[2] = X_1[2] - X_1[0] = 12 - 6 X_3 = [6, 3, 6] # -> X_3[1] = X_2[1] - X_2[0] = 9 - 6 X_4 = [6, 3, 3] # -> X_4[2] = X_3[2] - X_3[1] = 6 - 3 X_5 = [3, 3, 3] # -> X_5[1] = X_4[0] - X_4[1] = 6 - 3 The returning output is the sum of the final transformation (here 9). Example solution([6, 9, 21]) #-> 9 Solution steps: [6, 9, 12] #-> X[2] = 21 - 9 [6, 9, 6] #-> X[2] = 12 - 6 [6, 3, 6] #-> X[1] = 9 - 6 [6, 3, 3] #-> X[2] = 6 - 3 [3, 3, 3] #-> X[1] = 6 - 3

function solution(numbers) { // place to store the working array let workingArray = numbers; // place to store the previous array let previousArray = numbers; // while the previous array is not equal to the working array while (JSON.stringify(previousArray) !== JSON.stringify(workingArray)) { // store the previous array previousArray = workingArray; // loop through the array for (let i = 0; i < workingArray.length; i++) { // place to store the current number let currentNumber = workingArray[i]; // loop through the array again for (let j = i + 1; j < workingArray.length; j++) { // if the current number is greater than the other number if (currentNumber > workingArray[j]) { // subtract the other number from the current number currentNumber -= workingArray[j]; // replace the current number in the array with the new number workingArray[i] = currentNumber; // replace the other number in

Javascript
View
generate functionWed, 21 Jun 2023

You are designing a video game version of one of the most well known board games, chess. To start, you have decided to build the programming necessary to have a working digital pawn on your 8x8 chessboard. function findPawn(board) { Take a few chessboard arrays that have been created, check to see if you can move the pawn up one space, capture another pawn if possible, and promote the pawn to a Queen if it reaches the other side. You will not have to program for the "En Passant" maneuver for this exercise. In the array, spaces are represented by ' ', while any pawns are represented by 'p'. Queens are represented by 'Q'. should move the pawn one space should promote the pawn to a queen if it reaches the other side should attack another pawn if it is in the correct position

function findPawn(board) { let pawn = null; board.forEach((row, y) => { row.forEach((piece, x) => { if (piece === 'p') { pawn = [x, y]; } }); }); if (board[pawn[1] - 1][pawn[0]] === ' ') { board[pawn[1] - 1][pawn[0]] = 'p'; board[pawn[1]][pawn[0]] = ' '; } if (board[pawn[1] - 1][pawn[0] + 1] === 'p') { board[pawn[1] - 1][pawn[0] + 1] = ' '; } if (board[pawn[1] - 1][pawn[0] - 1] === 'p') { board[pawn[1] - 1][pawn[0] - 1] = ' '; } if (

Javascript
View
generate functionTue, 20 Jun 2023

Detective, we have a situation on our hands! The madman we've been hunting down got painted into a corner so he's holed up in the abandoned building that was scheduled to be torn down, with 4 innocent people as hostages. We still don't know who he is but we know he isMad. For each room, we want you to go through, see if anyone is there, and rescue them. But, we think the madman is hiding as one of the hostages. If you find him, don't bring him with you or he'll escape! You're the only one who can tell which one is the madman so we need you to find him. Return an array of the 4 hostages so we can have them accounted for, and then we'll sweep the building with the rest of the police so he can't possibly escape! You have a lot of rooms within rooms to search, so get cracking! const evilMaze = (maze) => {

const evilMaze = (maze) => { let results = [] let madman = false for(let i = 0; i < maze.length; i++) { if(typeof maze[i] === 'string') { if(maze[i] !== "madman") { results.push(maze[i]) } else { madman = true } } else { let r = evilMaze(maze[i]) if(madman === false) { results = results.concat(r) } else { results = results.concat(r.slice(0, r.indexOf("madman"))) } } } return results }

Javascript
View
generate functionWed, 21 Jun 2023

You are designing a video game version of one of the most well known board games, chess. To start, you have decided to build the programming necessary to have a working digital pawn on your 8x8 chessboard. function movePawn(board) { Take a few chessboard arrays that have been created, check to see if you can move the pawn up one space, capture another pawn if possible, and promote the pawn to a Queen if it reaches the other side. You will not have to program for the "En Passant" maneuver for this exercise. In the array, spaces are represented by ' ', while any pawns are represented by 'p'. Queens are represented by 'Q'. should move the pawn one space should promote the pawn to a queen if it reaches the other side should attack another pawn if it is in the correct position

// Test 1 var board = [' ',' ',' ',' ',' ',' ',' ',' ', ' ',' ',' ',' ',' ',' ',' ',' ', ' ',' ',' ',' ',' ',' ',' ',' ', ' ',' ',' ',' ',' ',' ',' ',' ', ' ',' ',' ',' ',' ',' ',' ',' ', ' ',' ',' ',' ',' ',' ',' ',' ', ' ',' ',' ',' ',' ',' ',' ',' ', ' ',' ',' ',' ',' ',' ',' ','p'] movePawn(board) // --> [' ',' ',' ',' ',' ',' ',' ',' ', // ' ',' ',' ',' ',' ',' ',' ',' ', // ' ',' ',' ',' ',' ',' ',' ',' ', // ' ',' ',' ',' ',' ',' ',' ',' ', // ' ',' ',' ',' ',' '

Javascript
View
generate functionWed, 07 Jun 2023

You're working on code that's extremely low level. we're talking BIOS and hardware level. You have a program that can do a lot of good stuff with data from the hardware, but it takes Hexadecimal codes, and the raw output of the hardware code is in Binary. You need a way using JavaScript to convert binary numbers into hexadecimal ones. You're going to receive the binary data in 8-bit chunks and you have to return it's hexadecimal value as a string. No function convertBinaryArrayToHex(arr) { return an array of hexadecimal values

function convertBinaryArrayToHex(arr) { var res = []; for (var i = 0; i < arr.length; i += 4) { var value = 0; for (var j = 0; j < 4; j++) { value += arr[i + j] << (3 - j); } res.push(value.toString(16)); } return res.join(''); }

Javascript
View
generate functionWed, 14 Jun 2023

You are tasked with creating a JavaScript function that calculates the total price of an online shop order, taking into account any applicable discounts. The shop offers the following discounts: If the order total is between $100 and $199, a 10% discount is applied. If the order total is between $200 and $499, a 20% discount is applied. If the order total is $500 or more, a 30% discount is applied. Write a function called calculateTotalPrice(items) that takes an array of objects representing the items in the order. Each object has the following properties: name: The name of the item (string). price: The price of the item (number). quantity: The quantity of the item being ordered (number). The function should return the total price of the order after applying any applicable discounts. There are no applicable discounts for single item purchases.

function calculateTotalPrice(items) { let totalPrice = 0; let discount = 0; for (let i = 0; i < items.length; i++) { totalPrice += items[i].price * items[i].quantity; } if (totalPrice >= 500) { discount = 0.3; } else if (totalPrice >= 200) { discount = 0.2; } else if (totalPrice >= 100) { discount = 0.1; } return totalPrice - (discount * totalPrice); }

Javascript
View
generate functionThu, 15 Jun 2023

Detective, you have 5 people, and they were at the scene of a crime. You are trying to figure out where they were, so you and your team have questioned the 5 suspects. The 5 suspects are: Alice, Bob, Charlie, Daisy, and Ethan. You have got the information but you think that there are some contradictions in what they're saying. For clarity, you and your team have written their statements so that they are all the same format. function compareStatements(people) { You have put each of the suspects and their information into an object as follows: const person1 = { name: 'Alice', statements: [ 'I was in the location', 'Bob was in the place', 'Charlie was not in the spot, 'Daisy was in the zone', 'Ethan was not in the room', ], }; Your objective is to compare the statements, and if any contradict, you want to put them into a nested array as part of a sub array, appending their name to their statement as follows: [['Alice: I was in the location', 'Bob: Alice was not in the location']] and return that array.

function compareStatements(people) { const contradictions = []; people.forEach(person => { person.statements.forEach((statement, index) => { people.forEach(person2 => { if (person.name !== person2.name && !contradictions.includes(person2.statements[index])) { contradictions.push(`${person.name}: ${statement}`, `${person2.name}: ${person2.statements[index]}`); } }); }); }); return contradictions; } const person1 = { name: 'Alice', statements: [ 'I was in the location', 'Bob was in the place', 'Charlie was not in the spot', 'Daisy was in the zone', 'Ethan was not in the room', ], }; const person2 = { name: 'Bob', statements: [ 'I was in the place', 'Alice was not in the location', 'Charlie

Javascript
View
generate functionThu, 15 Jun 2023

function compareStatements(people) { You have put each of the suspects and their information into an object as follows: const person1 = { name: 'Alice', statements: [ 'I was in the location', 'Bob was in the place', 'Charlie was not in the spot, 'Daisy was in the zone', 'Ethan was not in the room', ], }; Your objective is to compare the statements, and if any contradict, you want to put them into a nested array as part of a sub array, appending their name to their statement as follows: [['Alice: I was in the location', 'Bob: Alice was not in the location']] and return that array. Use the .includes() method instead of the == operator. Use if statement to add the contradicting statements to a nested array.

const person1 = { name: 'Alice', statements: [ 'I was in the location', 'Bob was in the place', 'Charlie was not in the spot', 'Daisy was in the zone', 'Ethan was not in the room', ], };

Javascript
View
generate functionThu, 11 May 2023

Write a function that takes in a number of hours, minutes, and seconds, counts down in real time, and returns "FInish!" at the end. If a person enters in seconds or minutes, greater than 60, or hours greater than 99, It should return "Invalid Seconds","Invalid Minutes", or "Invalid Hours",

function countDown(hours, minutes, seconds) { var hours = hours * 3600; var minutes = minutes * 60; var totalSeconds = seconds + minutes + hours; while (totalSeconds > 0) { process.stdout.write('\033c'); console.log(totalSeconds); totalSeconds--; } return 'Finish'; }

Javascript
View
generate functionTue, 20 Jun 2023

Detective, we have a situation on our hands! The madman we've been hunting down got painted into a corner so he's holed up in the abandoned building that was scheduled to be torn down, with 4 innocent people as hostages. We still don't know who he is but we know he isMad. For each room, we want you to go through, see if anyone is there, and rescue them. But, we think the madman is hiding as one of the hostages. If you find him, don't bring him with you or he'll escape! You're the only one who can tell which one is the madman so we need you to find him. Return an array of the 4 hostages so we can have them accounted for, and then we'll sweep the building with the rest of the police so he can't possibly escape! You have a lot of rooms within rooms to search, so get cracking! const evilMaze = (maze) => { return an array of objects

const evilMaze = (maze) => { let hostages = []; // write your code here! for(var i = 0; i < maze.length; i++){ if(maze[i].isMad === true){ continue; } if(Array.isArray(maze[i].room)){ hostages.push(maze[i].room[0]); } else{ hostages.push(maze[i]); } } return hostages; }

Javascript
View
generate functionThu, 15 Jun 2023

There is a secret string which is unknown to you. Given a collection of random triplets from the string, recover the original string. A triplet here is defined as a sequence of three letters such that each letter occurs somewhere before the next in the given string. "whi" is a triplet for the string "whatisup". As a simplification, you may assume that no letter occurs more than once in the secret string. You can assume nothing about the triplets given to you other than that they are valid triplets and that they contain sufficient information to deduce the original string. In particular, this means that the secret string will never contain letters that do not occur in one of the triplets given to you.

//incomplete function recoverSecret(triplets) { let flat = triplets.flat(); let unique = Array.from(new Set(flat)); console.log(unique); let result = ''; let first = triplets[0][0]; let last = triplets[triplets.length - 1][2]; let temp = ''; for (let i = 0; i < triplets.length; i++) { if (triplets[i].includes(first)) { temp += first; } } console.log(temp); return result; }

Javascript
View
generate functionFri, 09 Jun 2023

You've got a nifty little program that collects a bunch of data, but it's returning data as it comes in in the form of an array. The data coming in is in a random order. That's not so good, because you want to be able to easily read and use this information. To make the data easier to manage, use a for loop to sort out your data by its type. Return an array with all the values in it, sorted by letters first, followed by numbers, then objects. Be aware that your nifty program sometimes returns nested arrays with their own elements in them. function separateDataTypes(arr) { For example, an array of [1,a,[2,3],b] Should return as [a,b,1,2,3].

function separateDataTypes(arr) { var letter = []; var number = []; var object = []; var output = []; for(var i = 0; i < arr.length; i++){ if(typeof arr[i] === 'number'){ number.push(arr[i]); } else if(typeof arr[i] === 'string'){ letter.push(arr[i]); } else if(typeof arr[i] === 'object'){ object.push(arr[i]); } } return output.concat(letter, number, object); } separateDataTypes([1,a,[2,3],b])

Javascript
View
generate functionTue, 06 Jun 2023

Uh-oh, you've been given a nice opportunity to make some money... from the devil! It's quite simple. In a box of 25 drawers, there is a gold coin among them. all you have to do is find the coin, or else you lose your soul! Being a sporting person, the devil has 'graciously' allowed you to use your programming skills to find the gold coin. You have only one chance to open a drawer, so better put those programming skills to use! Find this object: {name: 'gold coin'} in a 2-dimensional array of objects provided to your function, findGoldCoin.

function findGoldCoin(drawers) { for(let i = 0; i < drawers.length; i++){ if(drawers[i][0].name === 'gold coin'){ return [0, i]; } for(let j = 0; j < drawers[i].length; j++){ if(drawers[i][j].name === 'gold coin'){ return [i, j]; } } } return `You lost your soul!`; }

Javascript
View
generate functionWed, 21 Jun 2023

You are designing a video game version of one of the most well known board games, chess. To start, you have decided to build the programming necessary to have a working digital pawn on your 8x8 chessboard. function movePawn(board) { Take a few chessboard arrays that have been created, check to see if you can move the pawn up one space, capture another pawn if possible, and promote the pawn to a Queen if it reaches the other side. You will not have to program for the "En Passant" maneuver for this exercise. In the array, spaces are represented by ' ', while any pawns are represented by 'p'. Queens are represented by 'Q'. should move the pawn one space should promote the pawn to a queen if it reaches the other side should attack another pawn if it is in the correct position

function movePawn(board) { let nextIndex, currentIndex = board.indexOf('p'); if (currentIndex < 8) { return board; } else { nextIndex = currentIndex - 8; } if (board[nextIndex] === 'p') { board[nextIndex] = 'p'; board.splice(currentIndex, 1, ' '); } else if (board[nextIndex] === ' ') { board[nextIndex] = 'p'; board.splice(currentIndex, 1, ' '); } else if (currentIndex >= 56 && board[nextIndex] === ' ') { board[nextIndex] = 'Q'; board.splice(currentIndex, 1, ' '); } return board; }

Javascript
View
generate functionWed, 21 Jun 2023

You are designing a video game version of one of the most well known board games, chess. To start, you have decided to build the programming necessary to have a working digital pawn on your 8x8 chessboard. function findPawn(board) { Take a few chessboard arrays that have been created, check to see if you can move the pawn up one space, capture another pawn if possible, and promote the pawn to a Queen if it reaches the other side. You will not have to program for the "En Passant" maneuver for this exercise. In the array, spaces are represented by ' ', while any pawns are represented by 'p'. Queens are represented by 'Q'. should move the pawn one space should promote the pawn to a queen if it reaches the other side should attack another pawn if it is in the correct position

function findPawn(board) { const position = board.findIndex(el => el.includes('p')) const row = board[position] const column = row.findIndex(el => el === 'p') if (position === 0) { board[position + 1] = board[position].slice(0, column) + ' ' + board[position][column + 1] return board } if (position === 7) { board[position] = board[position].slice(0, column) + 'Q' + board[position][column + 1] return board } if (board[position + 1][column - 1] === ' ') { board[position + 1] = board[position].slice(0, column) + ' ' + board[position][column + 1] return board } else if (board[position + 1][column + 1] === ' ') { board[position + 1] = board[position].slice(0, column) + ' ' + board[position

Javascript
View
generate functionFri, 09 Jun 2023

You've got a nifty little program that collects a bunch of data, but it's returning data as it comes in in the form of an array. The data coming in is in a random order. That's not so good, because you want to be able to easily read and use this information. To make the data easier to manage, use a for loop to sort out your data by its type. Return an array with all the values in it, sorted by letters first, followed by numbers, then objects. Be aware that your nifty program sometimes returns nested arrays with their own elements in them. function separateDataTypes(arr) {

function separateDataTypes(arr) { var stringArray = []; var numberArray = []; var objectArray = []; for (var i = 0; i < arr.length; i++){ if (typeof arr[i] === "string") { stringArray.push(arr[i]); } else if (typeof arr[i] === "number") { numberArray.push(arr[i]); } else if (typeof arr[i] === "object") { objectArray.push(arr[i]); } } return stringArray.concat(numberArray).concat(objectArray); } separateDataTypes([1, "a", "b", "c", 2, 3, 4, 5, null, {}, {}, {}]);

Javascript
View
generate functionMon, 15 May 2023

Your JavaScript function, swapNames, will be given a string including names, where the person's last name is followed by a comma and then the first name. You are to return a string with the same names but in first name then last name order, no commas. function swapNames(str) { Split the string by comma and create an array of names. should return the names in first name then last name order Use the split method of strings to split the input string and iterate over the resulting array. For each element, apply another split operation with the comma separator, then use array indexing to swap first and last names.

function swapNames(str) { var res = []; var arr = str.split(', '); for (var i = 0; i < arr.length; i++) { var obj = arr[i].split(' '); res.push(obj[1] + ' ' + obj[0]); } return res.join(', '); }

Javascript
View
generate functionTue, 13 Jun 2023

Your task is to create a JavaScript function that checks the strength of a given password. The strength of the password is determined based on the following criteria: The password must contain at least 8 characters. The password must contain at least one uppercase letter. The password must contain at least one lowercase letter. The password must contain at least one numeric digit. The password must contain at least one special character (e.g., !@#$%^&*). Write a function called checkPasswordStrength(password) that takes a string password as its parameter and returns a string indicating the strength of the password. The strength can be one of the following: "Very Weak" if the password contains less than 8 characters. "Weak" if the password contains 8 or more characters but fails to meet any other criteria. "Moderate" if the password contains 8 or more characters and meets at least two criteria. "Strong" if the password contains 8 or more characters and meets at least three criteria. "Very Strong" if the password contains 8 or more characters and meets all the criteria. Submit my code Hint

// create a variable with a string of the password // slice the string into an array // iterate through the array and check if it is uppercase // create a variable that conutns the uppercase letters and one that counts the special characters // return the string based on the number of uppercase letters and special characters

Javascript
View
generate functionWed, 21 Jun 2023

You are designing a video game version of one of the most well known board games, chess. To start, you have decided to build the programming necessary to have a working digital pawn on your 8x8 chessboard. function movePawn(board) { Take a few chessboard arrays that have been created, check to see if you can move the pawn up one space, capture another pawn if possible, and promote the pawn to a Queen if it reaches the other side. You will not have to program for the "En Passant" maneuver for this exercise. In the array, spaces are represented by ' ', while any pawns are represented by 'p'. Queens are represented by 'Q'. should move the pawn one space should promote the pawn to a queen if it reaches the other side should attack another pawn if it is in the correct position

function movePawn(board) { for (a = 0; a < board.length; a++) { for (b = 0; b < board.length; b++) { if (board[a][b] === 'p') { if (b === 0) { board[a][b] = ' '; board[a][b + 1] = 'p'; } else if (b === 7) { board[a][b] = 'Q'; } else if (board[a][b + 1] === ' ') { board[a][b] = ' '; board[a][b + 1] = 'p'; } else if (a + 1 < board.length && board[a + 1][b + 1] === 'p') { board[a][b] = ' '; board[a + 1][b + 1] = 'p'; } else if (a - 1 >= 0 && board[a - 1][b + 1] === 'p') { board[a

Javascript
View
generate functionTue, 06 Jun 2023

Uh-oh, you've been given a nice opportunity to make some money... from the devil! It's quite simple. In a box of 25 drawers, there is a gold coin among them. all you have to do is find the coin, or else you lose your soul! Being a sporting person, the devil has 'graciously' allowed you to use your programming skills to find the gold coin. You have only one chance to open a drawer, so better put those programming skills to use! use object literal Find this object: {name: 'gold coin'} in a 2-dimensional array of objects provided to your function, findGoldCoin.

function findGoldCoin(drawers) { for (var i = 0; i < drawers.length; i++) { for (var j = 0; j < drawers[i].length; j++) { if (drawers[i][j].name === 'gold coin') { return [i, j]; } } } return null; }

Javascript
View

Questions about programming?Chat with your personal AI assistant