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',
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
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
}
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);
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;
}
function recoverSecret(triplets) {
// ...
}
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;
}
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',
//
// 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',' ',' ',' ',' '],
[' ',' ',' ',' ',' ',' ',' ',' '],
[' ',' ',' ',' ',' ',' ',' ',' '],
[' ','
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
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 (
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
}
// Test 1
var board = [' ',' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ',' ',' ',' ',' ','p']
movePawn(board) // --> [' ',' ',' ',' ',' ',' ',' ',' ',
// ' ',' ',' ',' ',' ',' ',' ',' ',
// ' ',' ',' ',' ',' ',' ',' ',' ',
// ' ',' ',' ',' ',' ',' ',' ',' ',
// ' ',' ',' ',' ',' '
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('');
}
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);
}
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
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',
],
};
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';
}
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;
}
//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;
}
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])
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!`;
}
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;
}
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
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, {}, {}, {}]);
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(', ');
}
// 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
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
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;
}