Prompt:
//The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// >>> fibfib(1)
// 0
// >>> fibfib(5)
// 4
// >>> fibfib(8)
// 24
function fibfib(n){

const assert = require('node:assert');

function test() {
  let candidate = fibfib;
  assert.deepEqual(candidate(2),1);
  assert.deepEqual(candidate(1),0);
  assert.deepEqual(candidate(5),4);
  assert.deepEqual(candidate(8),24);
  assert.deepEqual(candidate(10),81);
  assert.deepEqual(candidate(12),274);
  assert.deepEqual(candidate(14),927);
}

test();


Prompt:
//Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// >>> vowels_count("abcde")
// 2
// >>> vowels_count("ACEDY")
// 3
function vowels_count(s){

const assert = require('node:assert');

function test() {
  let candidate = vowels_count;
  assert.deepEqual(candidate("abcde"),2);
  assert.deepEqual(candidate("Alone"),3);
  assert.deepEqual(candidate("key"),2);
  assert.deepEqual(candidate("bye"),1);
  assert.deepEqual(candidate("keY"),2);
  assert.deepEqual(candidate("bYe"),1);
  assert.deepEqual(candidate("ACEDY"),3);
}

test();


Prompt:
//Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// >>> circular_shift(12, 1)
// "21"
// >>> circular_shift(12, 2)
// "12"
function circular_shift(x, shift){

const assert = require('node:assert');

function test() {
  let candidate = circular_shift;
  assert.deepEqual(candidate(100, 2),"001");
  assert.deepEqual(candidate(12, 2),"12");
  assert.deepEqual(candidate(97, 8),"79");
  assert.deepEqual(candidate(12, 1),"21");
  assert.deepEqual(candidate(11, 101),"11");
}

test();


Prompt:
//Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// >>> digitSum("")
// 0
// >>> digitSum("abAB")
// 131
// >>> digitSum("abcCd")
// 67
// >>> digitSum("helloE")
// 69
// >>> digitSum("woArBld")
// 131
// >>> digitSum("aAaaaXa")
// 153
function digitSum(s){

const assert = require('node:assert');

function test() {
  let candidate = digitSum;
  assert.deepEqual(candidate(""),0);
  assert.deepEqual(candidate("abAB"),131);
  assert.deepEqual(candidate("abcCd"),67);
  assert.deepEqual(candidate("helloE"),69);
  assert.deepEqual(candidate("woArBld"),131);
  assert.deepEqual(candidate("aAaaaXa"),153);
  assert.deepEqual(candidate(" How are yOu?"),151);
  assert.deepEqual(candidate("You arE Very Smart"),327);
}

test();


Prompt:
//In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// >>> fruit_distribution("5 apples and 6 oranges", 19)
// 8
// >>> fruit_distribution("0 apples and 1 oranges", 3)
// 2
// >>> fruit_distribution("2 apples and 3 oranges", 100)
// 95
// >>> fruit_distribution("100 apples and 1 oranges", 120)
// 19
function fruit_distribution(s, n){

const assert = require('node:assert');

function test() {
  let candidate = fruit_distribution;
  assert.deepEqual(candidate("5 apples and 6 oranges", 19),8);
  assert.deepEqual(candidate("5 apples and 6 oranges", 21),10);
  assert.deepEqual(candidate("0 apples and 1 oranges", 3),2);
  assert.deepEqual(candidate("1 apples and 0 oranges", 3),2);
  assert.deepEqual(candidate("2 apples and 3 oranges", 100),95);
  assert.deepEqual(candidate("2 apples and 3 oranges", 5),0);
  assert.deepEqual(candidate("1 apples and 100 oranges", 120),19);
}

test();


Prompt:
//"Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in a list, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// >>> pluck([4, 2, 3])
// [2, 1]
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// >>> pluck([1, 2, 3])
// [2, 1]
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// >>> pluck([])
// []
// Example 4:
// >>> pluck([5, 0, 3, 0, 4, 2])
// [0, 1]
// Explanation: 0 is the smallest value, but  there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
function pluck(arr){

const assert = require('node:assert');

function test() {
  let candidate = pluck;
  assert.deepEqual(candidate([4, 2, 3]),[2, 1]);
  assert.deepEqual(candidate([1, 2, 3]),[2, 1]);
  assert.deepEqual(candidate([]),[]);
  assert.deepEqual(candidate([5, 0, 3, 0, 4, 2]),[0, 1]);
  assert.deepEqual(candidate([1, 2, 3, 0, 5, 3]),[0, 3]);
  assert.deepEqual(candidate([5, 4, 8, 4, 8]),[4, 1]);
  assert.deepEqual(candidate([7, 6, 7, 1]),[6, 1]);
  assert.deepEqual(candidate([7, 9, 7, 1]),[]);
}

test();


Prompt:
//You are given a non-empty list of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the list.
// If no such a value exist, return -1.
// Examples:
// >>> search([4, 1, 2, 2, 3, 1])
// 2
// >>> search([1, 2, 2, 3, 3, 3, 4, 4, 4])
// 3
// >>> search([5, 5, 4, 4, 4])
// -1
function search(lst){


Prompt:
//Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// >>> parse_nested_parens("(()()) ((())) () ((())()())")
// [2, 3, 1, 3]
function parse_nested_parens(paren_string){

const assert = require('node:assert');

function test() {
  let candidate = parse_nested_parens;
  assert.deepEqual(candidate("(()()) ((())) () ((())()())"),[2, 3, 1, 3]);
  assert.deepEqual(candidate("() (()) ((())) (((())))"),[1, 2, 3, 4]);
  assert.deepEqual(candidate("(()(())((())))"),[4]);
}

test();


Prompt:
//Given list of integers, return list in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// >>> strange_sort_list([1, 2, 3, 4])
// [1, 4, 2, 3]
// >>> strange_sort_list([5, 5, 5, 5])
// [5, 5, 5, 5]
// >>> strange_sort_list([])
// []
function strange_sort_list(lst){

const assert = require('node:assert');

function test() {
  let candidate = strange_sort_list;
  assert.deepEqual(candidate([1, 2, 3, 4]),[1, 4, 2, 3]);
  assert.deepEqual(candidate([5, 6, 7, 8, 9]),[5, 9, 6, 8, 7]);
  assert.deepEqual(candidate([1, 2, 3, 4, 5]),[1, 5, 2, 4, 3]);
  assert.deepEqual(candidate([5, 6, 7, 8, 9, 1]),[1, 9, 5, 8, 6, 7]);
  assert.deepEqual(candidate([5, 5, 5, 5]),[5, 5, 5, 5]);
  assert.deepEqual(candidate([]),[]);
  assert.deepEqual(candidate([1, 2, 3, 4, 5, 6, 7, 8]),[1, 8, 2, 7, 3, 6, 4, 5]);
  assert.deepEqual(candidate([0, 2, 2, 2, 5, 5, -5, -5]),[-5, 5, -5, 5, 0, 2, 2, 2]);
  assert.deepEqual(candidate([111111]),[111111]);
}

test();


Prompt:
//Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// >>> triangle_area(3, 4, 5)
// 6.0
// >>> triangle_area(1, 2, 10)
// -1
function triangle_area(a, b, c){

const assert = require('node:assert');

function test() {
  let candidate = triangle_area;
  assert.deepEqual(candidate(3, 4, 5),6.0);
  assert.deepEqual(candidate(1, 2, 10),-1);
  assert.deepEqual(candidate(4, 8, 5),8.18);
  assert.deepEqual(candidate(2, 2, 2),1.73);
  assert.deepEqual(candidate(1, 2, 3),-1);
  assert.deepEqual(candidate(10, 5, 7),16.25);
  assert.deepEqual(candidate(2, 6, 3),-1);
  assert.deepEqual(candidate(1, 1, 1),0.43);
  assert.deepEqual(candidate(2, 2, 10),-1);
}

test();


Prompt:
//Write a function that returns True if the object q will fly, and False otherwise.
// The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// >>> will_it_fly([1, 2], 5)
// false
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// >>> will_it_fly([3, 2, 3], 1)
// false
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// >>> will_it_fly([3, 2, 3], 9)
// true
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// >>> will_it_fly([3], 5)
// true
// # 3 is less than the maximum possible weight, and it's balanced.
function will_it_fly(q, w){

const assert = require('node:assert');

function test() {
  let candidate = will_it_fly;
  assert.deepEqual(candidate([3, 2, 3], 9),true);
  assert.deepEqual(candidate([1, 2], 5),false);
  assert.deepEqual(candidate([3], 5),true);
  assert.deepEqual(candidate([3, 2, 3], 1),false);
  assert.deepEqual(candidate([1, 2, 3], 6),false);
  assert.deepEqual(candidate([5], 5),true);
}

test();


Prompt:
//Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// >>> smallest_change([1, 2, 3, 5, 4, 7, 9, 6])
// 4
// >>> smallest_change([1, 2, 3, 4, 3, 2, 2])
// 1
// >>> smallest_change([1, 2, 3, 2, 1])
// 0
function smallest_change(arr){

const assert = require('node:assert');

function test() {
  let candidate = smallest_change;
  assert.deepEqual(candidate([1, 2, 3, 5, 4, 7, 9, 6]),4);
  assert.deepEqual(candidate([1, 2, 3, 4, 3, 2, 2]),1);
  assert.deepEqual(candidate([1, 4, 2]),1);
  assert.deepEqual(candidate([1, 4, 4, 2]),1);
  assert.deepEqual(candidate([1, 2, 3, 2, 1]),0);
  assert.deepEqual(candidate([3, 1, 1, 3]),0);
  assert.deepEqual(candidate([1]),0);
  assert.deepEqual(candidate([0, 1]),1);
}

test();


Prompt:
//Write a function that accepts two lists of strings and returns the list that has
// total number of chars in the all strings of the list less than the other list.
// if the two lists have the same number of chars, return the first list.
// Examples
// >>> total_match([], [])
// []
// >>> total_match(["hi", "admin"], ["hI", "Hi"])
// ["hI", "Hi"]
// >>> total_match(["hi", "admin"], ["hi", "hi", "admin", "project"])
// ["hi", "admin"]
// >>> total_match(["hi", "admin"], ["hI", "hi", "hi"])
// ["hI", "hi", "hi"]
// >>> total_match(["4"], ["1", "2", "3", "4", "5"])
// ["4"]
function total_match(lst1, lst2){

const assert = require('node:assert');

function test() {
  let candidate = total_match;
  assert.deepEqual(candidate([], []),[]);
  assert.deepEqual(candidate(["hi", "admin"], ["hi", "hi"]),["hi", "hi"]);
  assert.deepEqual(candidate(["hi", "admin"], ["hi", "hi", "admin", "project"]),["hi", "admin"]);
  assert.deepEqual(candidate(["4"], ["1", "2", "3", "4", "5"]),["4"]);
  assert.deepEqual(candidate(["hi", "admin"], ["hI", "Hi"]),["hI", "Hi"]);
  assert.deepEqual(candidate(["hi", "admin"], ["hI", "hi", "hi"]),["hI", "hi", "hi"]);
  assert.deepEqual(candidate(["hi", "admin"], ["hI", "hi", "hii"]),["hi", "admin"]);
  assert.deepEqual(candidate([], ["this"]),[]);
  assert.deepEqual(candidate(["this"], []),[]);
}

test();


Prompt:
//Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// >>> is_multiply_prime(30)
// true
// 30 = 2 * 3 * 5
function is_multiply_prime(a){

const assert = require('node:assert');

function test() {
  let candidate = is_multiply_prime;
  assert.deepEqual(candidate(5),false);
  assert.deepEqual(candidate(30),true);
  assert.deepEqual(candidate(8),true);
  assert.deepEqual(candidate(10),false);
  assert.deepEqual(candidate(125),true);
  assert.deepEqual(candidate(105),true);
  assert.deepEqual(candidate(126),false);
  assert.deepEqual(candidate(729),false);
  assert.deepEqual(candidate(891),false);
  assert.deepEqual(candidate(1001),true);
}

test();


Prompt:
//Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// >>> is_simple_power(1, 4)
// true
// >>> is_simple_power(2, 2)
// true
// >>> is_simple_power(8, 2)
// true
// >>> is_simple_power(3, 2)
// false
// >>> is_simple_power(3, 1)
// false
// >>> is_simple_power(5, 3)
// false
function is_simple_power(x, n){

const assert = require('node:assert');

function test() {
  let candidate = is_simple_power;
  assert.deepEqual(candidate(16, 2),true);
  assert.deepEqual(candidate(143214, 16),false);
  assert.deepEqual(candidate(4, 2),true);
  assert.deepEqual(candidate(9, 3),true);
  assert.deepEqual(candidate(16, 4),true);
  assert.deepEqual(candidate(24, 2),false);
  assert.deepEqual(candidate(128, 4),false);
  assert.deepEqual(candidate(12, 6),false);
  assert.deepEqual(candidate(1, 1),true);
  assert.deepEqual(candidate(1, 12),true);
}

test();


Prompt:
//Write a function that takes an integer a and returns True
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// >>> iscube(1)
// true
// >>> iscube(2)
// false
// >>> iscube(-1)
// true
// >>> iscube(64)
// true
// >>> iscube(0)
// true
// >>> iscube(180)
// false
function iscube(a){

const assert = require('node:assert');

function test() {
  let candidate = iscube;
  assert.deepEqual(candidate(1),true);
  assert.deepEqual(candidate(2),false);
  assert.deepEqual(candidate(-1),true);
  assert.deepEqual(candidate(64),true);
  assert.deepEqual(candidate(180),false);
  assert.deepEqual(candidate(1000),true);
  assert.deepEqual(candidate(0),true);
  assert.deepEqual(candidate(1729),false);
}

test();


Prompt:
//You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// >>> hex_key("AB")
// 1
// >>> hex_key("1077E")
// 2
// >>> hex_key("ABED1A33")
// 4
// >>> hex_key("123456789ABCDEF0")
// 6
// >>> hex_key("2020")
// 2
function hex_key(num){

const assert = require('node:assert');

function test() {
  let candidate = hex_key;
  assert.deepEqual(candidate("AB"),1);
  assert.deepEqual(candidate("1077E"),2);
  assert.deepEqual(candidate("ABED1A33"),4);
  assert.deepEqual(candidate("2020"),2);
  assert.deepEqual(candidate("123456789ABCDEF0"),6);
  assert.deepEqual(candidate("112233445566778899AABBCCDDEEFF00"),12);
}

test();


Prompt:
//You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// >>> decimal_to_binary(15)
// "db1111db"
// >>> decimal_to_binary(32)
// "db100000db"
function decimal_to_binary(decimal){

const assert = require('node:assert');

function test() {
  let candidate = decimal_to_binary;
  assert.deepEqual(candidate(0),"db0db");
  assert.deepEqual(candidate(32),"db100000db");
  assert.deepEqual(candidate(103),"db1100111db");
  assert.deepEqual(candidate(15),"db1111db");
}

test();


Prompt:
//Filter an input list of strings only for ones that contain given substring
// >>> filter_by_substring([], "a")
// []
// >>> filter_by_substring(["abc", "bacd", "cde", "array"], "a")
// ["abc", "bacd", "array"]
function filter_by_substring(strings, substring){

const assert = require('node:assert');

function test() {
  let candidate = filter_by_substring;
  assert.deepEqual(candidate([], "john"),[]);
  assert.deepEqual(candidate(["xxx", "asd", "xxy", "john doe", "xxxAAA", "xxx"], "xxx"),["xxx", "xxxAAA", "xxx"]);
  assert.deepEqual(candidate(["xxx", "asd", "aaaxxy", "john doe", "xxxAAA", "xxx"], "xx"),["xxx", "aaaxxy", "xxxAAA", "xxx"]);
  assert.deepEqual(candidate(["grunt", "trumpet", "prune", "gruesome"], "run"),["grunt", "prune"]);
}

test();


Prompt:
//You are given a string s.
// Your task is to check if the string is happy or not.
// A string is happy if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// >>> is_happy("a")
// false
// >>> is_happy("aa")
// false
// >>> is_happy("abcd")
// true
// >>> is_happy("aabb")
// false
// >>> is_happy("adb")
// true
// >>> is_happy("xyy")
// false
function is_happy(s){

const assert = require('node:assert');

function test() {
  let candidate = is_happy;
  assert.deepEqual(candidate("a"),false);
  assert.deepEqual(candidate("aa"),false);
  assert.deepEqual(candidate("abcd"),true);
  assert.deepEqual(candidate("aabb"),false);
  assert.deepEqual(candidate("adb"),true);
  assert.deepEqual(candidate("xyy"),false);
  assert.deepEqual(candidate("iopaxpoi"),true);
  assert.deepEqual(candidate("iopaxioi"),false);
}

test();


Prompt:
//It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you a list of GPAs for some students and you have to write
// a function that can output a list of letter grades using the following table:
// GPA       |    Letter grade
// 4.0                A+
// > 3.7                A
// > 3.3                A-
// > 3.0                B+
// > 2.7                B
// > 2.3                B-
// > 2.0                C+
// > 1.7                C
// > 1.3                C-
// > 1.0                D+
// > 0.7                D
// > 0.0                D-
// 0.0                E
// Example:
// >>> grade_equation([4.0, 3, 1.7, 2, 3.5])
// ["A+", "B", "C-", "C", "A-"]
function numerical_letter_grade(grades){

const assert = require('node:assert');

function test() {
  let candidate = numerical_letter_grade;
  assert.deepEqual(candidate([4.0, 3, 1.7, 2, 3.5]),["A+", "B", "C-", "C", "A-"]);
  assert.deepEqual(candidate([1.2]),["D+"]);
  assert.deepEqual(candidate([0.5]),["D-"]);
  assert.deepEqual(candidate([0.0]),["E"]);
  assert.deepEqual(candidate([1.0, 0.3, 1.5, 2.8, 3.3]),["D", "D-", "C-", "B", "B+"]);
  assert.deepEqual(candidate([0.0, 0.7]),["E", "D-"]);
}

test();


Prompt:
//Write a function that takes a string and returns True if the string
// length is a prime number or False otherwise
// Examples
// >>> prime_length("Hello")
// true
// >>> prime_length("abcdcba")
// true
// >>> prime_length("kittens")
// true
// >>> prime_length("orange")
// false
function prime_length(string){

const assert = require('node:assert');

function test() {
  let candidate = prime_length;
  assert.deepEqual(candidate("Hello"),true);
  assert.deepEqual(candidate("abcdcba"),true);
  assert.deepEqual(candidate("kittens"),true);
  assert.deepEqual(candidate("orange"),false);
  assert.deepEqual(candidate("wow"),true);
  assert.deepEqual(candidate("world"),true);
  assert.deepEqual(candidate("MadaM"),true);
  assert.deepEqual(candidate("Wow"),true);
  assert.deepEqual(candidate(""),false);
  assert.deepEqual(candidate("HI"),true);
  assert.deepEqual(candidate("go"),true);
  assert.deepEqual(candidate("gogo"),false);
  assert.deepEqual(candidate("aaaaaaaaaaaaaaa"),false);
  assert.deepEqual(candidate("Madam"),true);
  assert.deepEqual(candidate("M"),false);
  assert.deepEqual(candidate("0"),false);
}

test();


Prompt:
//Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
function starts_one_ends(n){

const assert = require('node:assert');

function test() {
  let candidate = starts_one_ends;
  assert.deepEqual(candidate(1),1);
  assert.deepEqual(candidate(2),18);
  assert.deepEqual(candidate(3),180);
  assert.deepEqual(candidate(4),1800);
  assert.deepEqual(candidate(5),18000);
}

test();


Prompt:
//Given a positive integer N, return the total sum of its digits in binary.
// Example
// >>> solve(1000)
// "1"
// >>> solve(150)
// "110"
// >>> solve(147)
// "1100"
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
function solve(N){

const assert = require('node:assert');

function test() {
  let candidate = solve;
  assert.deepEqual(candidate(1000),"1");
  assert.deepEqual(candidate(150),"110");
  assert.deepEqual(candidate(147),"1100");
  assert.deepEqual(candidate(333),"1001");
  assert.deepEqual(candidate(963),"10010");
}

test();


Prompt:
//Given a non-empty list of integers lst. add the even elements that are at odd indices..
// Examples:
// >>> add([4, 2, 6, 7])
// 2
function add(lst){

const assert = require('node:assert');

function test() {
  let candidate = add;
  assert.deepEqual(candidate([4, 88]),88);
  assert.deepEqual(candidate([4, 5, 6, 7, 2, 122]),122);
  assert.deepEqual(candidate([4, 0, 6, 7]),0);
  assert.deepEqual(candidate([4, 4, 6, 8]),12);
}

test();


Prompt:
//Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// >>> anti_shuffle("Hi")
// "Hi"
// >>> anti_shuffle("hello")
// "ehllo"
// >>> anti_shuffle("Hello World!!!")
// "Hello !!!Wdlor"
function anti_shuffle(s){

const assert = require('node:assert');

function test() {
  let candidate = anti_shuffle;
  assert.deepEqual(candidate("Hi"),"Hi");
  assert.deepEqual(candidate("hello"),"ehllo");
  assert.deepEqual(candidate("number"),"bemnru");
  assert.deepEqual(candidate("abcd"),"abcd");
  assert.deepEqual(candidate("Hello World!!!"),"Hello !!!Wdlor");
  assert.deepEqual(candidate(""),"");
  assert.deepEqual(candidate("Hi. My name is Mister Robot. How are you?"),".Hi My aemn is Meirst .Rboot How aer ?ouy");
}

test();


Prompt:
//You are given a 2 dimensional data, as a nested lists,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the list,
// and return list of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// >>> get_row([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], 1)
// [[0, 0], [1, 4], [1, 0], [2, 5], [2, 0]]
// >>> get_row([], 1)
// []
// >>> get_row([[], [1], [1, 2, 3]], 3)
// [[2, 2]]
function get_row(lst, x){


Prompt:
//Given an array of non-negative integers, return a copy of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// >>> sort_array([])
// []
// >>> sort_array([5])
// [5]
// >>> sort_array([2, 4, 3, 0, 1, 5])
// [0, 1, 2, 3, 4, 5]
// >>> sort_array([2, 4, 3, 0, 1, 5, 6])
// [6, 5, 4, 3, 2, 1, 0]
function sort_array(array){

const assert = require('node:assert');

function test() {
  let candidate = sort_array;
  assert.deepEqual(candidate([]),[]);
  assert.deepEqual(candidate([5]),[5]);
  assert.deepEqual(candidate([2, 4, 3, 0, 1, 5]),[0, 1, 2, 3, 4, 5]);
  assert.deepEqual(candidate([2, 4, 3, 0, 1, 5, 6]),[6, 5, 4, 3, 2, 1, 0]);
  assert.deepEqual(candidate([2, 1]),[1, 2]);
  assert.deepEqual(candidate([15, 42, 87, 32, 11, 0]),[0, 11, 15, 32, 42, 87]);
  assert.deepEqual(candidate([21, 14, 23, 11]),[23, 21, 14, 11]);
}

test();


Prompt:
//Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// >>> encrypt("hi")
// "lm"
// >>> encrypt("asdfghjkl")
// "ewhjklnop"
// >>> encrypt("gf")
// "kj"
// >>> encrypt("et")
// "ix"
function encrypt(s){

const assert = require('node:assert');

function test() {
  let candidate = encrypt;
  assert.deepEqual(candidate("hi"),"lm");
  assert.deepEqual(candidate("asdfghjkl"),"ewhjklnop");
  assert.deepEqual(candidate("gf"),"kj");
  assert.deepEqual(candidate("et"),"ix");
  assert.deepEqual(candidate("faewfawefaewg"),"jeiajeaijeiak");
  assert.deepEqual(candidate("hellomyfriend"),"lippsqcjvmirh");
  assert.deepEqual(candidate("dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh"),"hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl");
  assert.deepEqual(candidate("a"),"e");
}

test();


Prompt:
//For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// >>> sum_product([])
// [0, 1]
// >>> sum_product([1, 2, 3, 4])
// [10, 24]
function sum_product(numbers){

const assert = require('node:assert');

function test() {
  let candidate = sum_product;
  assert.deepEqual(candidate([]),[0, 1]);
  assert.deepEqual(candidate([1, 1, 1]),[3, 1]);
  assert.deepEqual(candidate([100, 0]),[100, 0]);
  assert.deepEqual(candidate([3, 5, 7]),[15, 105]);
  assert.deepEqual(candidate([10]),[10, 10]);
}

test();


Prompt:
//You are given a list of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the list.
// Return None if there is no such element.
// >>> next_smallest([1, 2, 3, 4, 5])
// 2
// >>> next_smallest([5, 1, 4, 3, 2])
// 2
// >>> next_smallest([])
// undefined
// >>> next_smallest([1, 1])
// undefined
function next_smallest(lst){

const assert = require('node:assert');

function test() {
  let candidate = next_smallest;
  assert.deepEqual(candidate([1, 2, 3, 4, 5]),2);
  assert.deepEqual(candidate([5, 1, 4, 3, 2]),2);
  assert.deepEqual(candidate([]),undefined);
  assert.deepEqual(candidate([1, 1]),undefined);
  assert.deepEqual(candidate([1, 1, 1, 1, 0]),1);
  assert.deepEqual(candidate([1, 1]),undefined);
  assert.deepEqual(candidate([-35, 34, 12, -45]),-35);
}

test();


Prompt:
//You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// >>> is_bored("Hello world")
// 0
// >>> is_bored("The sky is blue. The sun is shining. I love this weather")
// 1
function is_bored(S){

const assert = require('node:assert');

function test() {
  let candidate = is_bored;
  assert.deepEqual(candidate("Hello world"),0);
  assert.deepEqual(candidate("Is the sky blue?"),0);
  assert.deepEqual(candidate("I love It !"),1);
  assert.deepEqual(candidate("bIt"),0);
  assert.deepEqual(candidate("I feel good today. I will be productive. will kill It"),2);
  assert.deepEqual(candidate("You and I are going for a walk"),0);
}

test();


Prompt:
//Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// >>> any_int(5, 2, 7)
// true
// >>> any_int(3, 2, 2)
// false
// >>> any_int(3, -2, 1)
// true
// >>> any_int(3.6, -2.2, 2)
// false
function any_int(x, y, z){

const assert = require('node:assert');

function test() {
  let candidate = any_int;
  assert.deepEqual(candidate(2, 3, 1),true);
  assert.deepEqual(candidate(2.5, 2, 3),false);
  assert.deepEqual(candidate(1.5, 5, 3.5),false);
  assert.deepEqual(candidate(2, 6, 2),false);
  assert.deepEqual(candidate(4, 2, 2),true);
  assert.deepEqual(candidate(2.2, 2.2, 2.2),false);
  assert.deepEqual(candidate(-4, 6, 2),true);
  assert.deepEqual(candidate(2, 1, 1),true);
  assert.deepEqual(candidate(3, 4, 7),true);
  assert.deepEqual(candidate(3.0, 4, 7),false);
}

test();


Prompt:
//Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// >>> encode("test")
// "TGST"
// >>> encode("This is a message")
// "tHKS KS C MGSSCGG"
function encode(message){

const assert = require('node:assert');

function test() {
  let candidate = encode;
  assert.deepEqual(candidate("TEST"),"tgst");
  assert.deepEqual(candidate("Mudasir"),"mWDCSKR");
  assert.deepEqual(candidate("YES"),"ygs");
  assert.deepEqual(candidate("This is a message"),"tHKS KS C MGSSCGG");
  assert.deepEqual(candidate("I DoNt KnOw WhAt tO WrItE"),"k dQnT kNqW wHcT Tq wRkTg");
}

test();


Prompt:
//You are given a list of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// >>> skjkasdkd([0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3])
// 10
// >>> skjkasdkd([1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1])
// 25
// >>> skjkasdkd([1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3])
// 13
// >>> skjkasdkd([0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6])
// 11
// >>> skjkasdkd([0, 81, 12, 3, 1, 21])
// 3
// >>> skjkasdkd([0, 8, 1, 2, 1, 7])
// 7
function skjkasdkd(lst){


Prompt:
//Given a dictionary, return True if all keys are strings in lower
// case or all keys are strings in upper case, else return False.
// The function should return False is the given dictionary is empty.
// Examples:
// >>> check_dict_case({"a": "apple", "b": "banana"})
// true
// >>> check_dict_case({"a": "apple", "A": "banana", "B": "banana"})
// false
// >>> check_dict_case({"a": "apple", 8: "banana", "a": "apple"})
// false
// >>> check_dict_case({"Name": "John", "Age": "36", "City": "Houston"})
// false
// >>> check_dict_case({"STATE": "NC", "ZIP": "12345"})
// true
function check_dict_case(dict){

const assert = require('node:assert');

function test() {
  let candidate = check_dict_case;
  assert.deepEqual(candidate({"p": "pineapple", "b": "banana"}),true);
  assert.deepEqual(candidate({"p": "pineapple", "A": "banana", "B": "banana"}),false);
  assert.deepEqual(candidate({"p": "pineapple", "5": "banana", "a": "apple"}),false);
  assert.deepEqual(candidate({"Name": "John", "Age": "36", "City": "Houston"}),false);
  assert.deepEqual(candidate({"STATE": "NC", "ZIP": "12345"}),true);
  assert.deepEqual(candidate({"fruit": "Orange", "taste": "Sweet"}),true);
  assert.deepEqual(candidate({}),false);
}

test();


Prompt:
//Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// >>> count_up_to(5)
// [2, 3]
// >>> count_up_to(11)
// [2, 3, 5, 7]
// >>> count_up_to(0)
// []
// >>> count_up_to(20)
// [2, 3, 5, 7, 11, 13, 17, 19]
// >>> count_up_to(1)
// []
// >>> count_up_to(18)
// [2, 3, 5, 7, 11, 13, 17]
function count_up_to(n){

const assert = require('node:assert');

function test() {
  let candidate = count_up_to;
  assert.deepEqual(candidate(5),[2, 3]);
  assert.deepEqual(candidate(6),[2, 3, 5]);
  assert.deepEqual(candidate(7),[2, 3, 5]);
  assert.deepEqual(candidate(10),[2, 3, 5, 7]);
  assert.deepEqual(candidate(0),[]);
  assert.deepEqual(candidate(22),[2, 3, 5, 7, 11, 13, 17, 19]);
  assert.deepEqual(candidate(1),[]);
  assert.deepEqual(candidate(18),[2, 3, 5, 7, 11, 13, 17]);
  assert.deepEqual(candidate(47),[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]);
  assert.deepEqual(candidate(101),[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]);
}

test();


Prompt:
//Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// >>> multiply(148, 412)
// 16
// >>> multiply(19, 28)
// 72
// >>> multiply(2020, 1851)
// 0
// >>> multiply(14, -15)
// 20
function multiply(a, b){

const assert = require('node:assert');

function test() {
  let candidate = multiply;
  assert.deepEqual(candidate(148, 412),16);
  assert.deepEqual(candidate(19, 28),72);
  assert.deepEqual(candidate(2020, 1851),0);
  assert.deepEqual(candidate(14, -15),20);
  assert.deepEqual(candidate(76, 67),42);
  assert.deepEqual(candidate(17, 27),49);
  assert.deepEqual(candidate(0, 1),0);
  assert.deepEqual(candidate(0, 0),0);
}

test();


Prompt:
//Given a string s, count the number of uppercase vowels in even indices.
// For example:
// >>> count_upper("aBCdEf")
// 1
// >>> count_upper("abcdefg")
// 0
// >>> count_upper("dBBE")
// 0
function count_upper(s){

const assert = require('node:assert');

function test() {
  let candidate = count_upper;
  assert.deepEqual(candidate("aBCdEf"),1);
  assert.deepEqual(candidate("abcdefg"),0);
  assert.deepEqual(candidate("dBBE"),0);
  assert.deepEqual(candidate("B"),0);
  assert.deepEqual(candidate("U"),1);
  assert.deepEqual(candidate(""),0);
  assert.deepEqual(candidate("EEEE"),2);
}

test();


Prompt:
//Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// >>> closest_integer("10")
// 10
// >>> closest_integer("15.3")
// 15
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
function closest_integer(value){

const assert = require('node:assert');

function test() {
  let candidate = closest_integer;
  assert.deepEqual(candidate("10"),10);
  assert.deepEqual(candidate("14.5"),15);
  assert.deepEqual(candidate("-15.5"),-16);
  assert.deepEqual(candidate("15.3"),15);
  assert.deepEqual(candidate("0"),0);
}

test();


Prompt:
//From a given list of integers, generate a list of rolling maximum element found until given moment
// in the sequence.
// >>> rolling_max([1, 2, 3, 2, 3, 4, 2])
// [1, 2, 3, 3, 3, 4, 4]
function rolling_max(numbers){

const assert = require('node:assert');

function test() {
  let candidate = rolling_max;
  assert.deepEqual(candidate([]),[]);
  assert.deepEqual(candidate([1, 2, 3, 4]),[1, 2, 3, 4]);
  assert.deepEqual(candidate([4, 3, 2, 1]),[4, 4, 4, 4]);
  assert.deepEqual(candidate([3, 2, 3, 100, 3]),[3, 3, 3, 100, 100]);
}

test();