Prompt:
//This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// >>> choose_num(12, 15)
// 14
// >>> choose_num(13, 12)
// -1
function choose_num(x, y){

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

function test() {
  let candidate = choose_num;
  assert.deepEqual(candidate(12, 15),14);
  assert.deepEqual(candidate(13, 12),-1);
  assert.deepEqual(candidate(33, 12354),12354);
  assert.deepEqual(candidate(5234, 5233),-1);
  assert.deepEqual(candidate(6, 29),28);
  assert.deepEqual(candidate(27, 10),-1);
  assert.deepEqual(candidate(7, 7),-1);
  assert.deepEqual(candidate(546, 546),546);
}

test();


Prompt:
//Create a function that returns an array (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as undefined.
// Examples:
// >>> largest_smallest_integers([2, 4, 1, 3, 5, 7])
// [undefined, 1]
// >>> largest_smallest_integers([])
// [undefined, undefined]
// >>> largest_smallest_integers([0])
// [undefined, undefined]
function largest_smallest_integers(lst){

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

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

test();


Prompt:
//Given a string, find out how many distinct characters (regardless of case) does it consist of
// >>> count_distinct_characters("xyzXYZ")
// 3
// >>> count_distinct_characters("Jerry")
// 4
function count_distinct_characters(string){

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

function test() {
  let candidate = count_distinct_characters;
  assert.deepEqual(candidate(""),0);
  assert.deepEqual(candidate("abcde"),5);
  assert.deepEqual(candidate("abcdecadeCADE"),5);
  assert.deepEqual(candidate("aaaaAAAAaaaa"),1);
  assert.deepEqual(candidate("Jerry jERRY JeRRRY"),5);
}

test();


Prompt:
//Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// >>> make_a_pile(3)
// [3, 5, 7]
function make_a_pile(n){

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

function test() {
  let candidate = make_a_pile;
  assert.deepEqual(candidate(3),[3, 5, 7]);
  assert.deepEqual(candidate(4),[4, 6, 8, 10]);
  assert.deepEqual(candidate(5),[5, 7, 9, 11, 13]);
  assert.deepEqual(candidate(6),[6, 8, 10, 12, 14, 16]);
  assert.deepEqual(candidate(8),[8, 10, 12, 14, 16, 18, 20, 22]);
}

test();


Prompt:
//You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return undefined for empty arr.
// Example:
// >>> prod_signs([1, 2, 2, -4])
// 9
// >>> prod_signs([0, 1])
// 0
// >>> prod_signs([])
// undefined
function prod_signs(arr){

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

function test() {
  let candidate = prod_signs;
  assert.deepEqual(candidate([1, 2, 2, -4]),-9);
  assert.deepEqual(candidate([0, 1]),0);
  assert.deepEqual(candidate([1, 1, 1, 2, 3, -1, 1]),-10);
  assert.deepEqual(candidate([]),undefined);
  assert.deepEqual(candidate([2, 4, 1, 2, -1, -1, 9]),20);
  assert.deepEqual(candidate([-1, 1, -1, 1]),4);
  assert.deepEqual(candidate([-1, 1, 1, 1]),-4);
  assert.deepEqual(candidate([-1, 1, 1, 0]),0);
}

test();


Prompt:
//Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// >>> minSubArraySum([2, 3, 4, 1, 2, 4])
// 1
// >>> minSubArraySum([-1, -2, -3])
// -6
function minSubArraySum(nums){

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

function test() {
  let candidate = minSubArraySum;
  assert.deepEqual(candidate([2, 3, 4, 1, 2, 4]),1);
  assert.deepEqual(candidate([-1, -2, -3]),-6);
  assert.deepEqual(candidate([-1, -2, -3, 2, -10]),-14);
  assert.deepEqual(candidate([-9999999999999999]),-9999999999999999);
  assert.deepEqual(candidate([0, 10, 20, 1000000]),0);
  assert.deepEqual(candidate([-1, -2, -3, 10, -5]),-6);
  assert.deepEqual(candidate([100, -1, -2, -3, 10, -5]),-6);
  assert.deepEqual(candidate([10, 11, 13, 8, 3, 4]),3);
  assert.deepEqual(candidate([100, -33, 32, -1, 0, -2]),-33);
  assert.deepEqual(candidate([-10]),-10);
  assert.deepEqual(candidate([7]),7);
  assert.deepEqual(candidate([1, -1]),-1);
}

test();


Prompt:
//Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// >>> string_sequence(0)
// "0"
// >>> string_sequence(5)
// "0 1 2 3 4 5"
function string_sequence(n){

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

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

test();


Prompt:
//You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// >>> cycpattern_check("abcd", "abd")
// false
// >>> cycpattern_check("hello", "ell")
// true
// >>> cycpattern_check("whassup", "psus")
// false
// >>> cycpattern_check("abab", "baa")
// true
// >>> cycpattern_check("efef", "eeff")
// false
// >>> cycpattern_check("himenss", "simen")
// true
function cycpattern_check(a, b){

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

function test() {
  let candidate = cycpattern_check;
  assert.deepEqual(candidate("xyzw", "xyw"),false);
  assert.deepEqual(candidate("yello", "ell"),true);
  assert.deepEqual(candidate("whattup", "ptut"),false);
  assert.deepEqual(candidate("efef", "fee"),true);
  assert.deepEqual(candidate("abab", "aabb"),false);
  assert.deepEqual(candidate("winemtt", "tinem"),true);
}

test();


Prompt:
//Return true is array elements are monotonically increasing or decreasing.
// >>> monotonic([1, 2, 4, 20])
// true
// >>> monotonic([1, 20, 4, 10])
// false
// >>> monotonic([4, 1, 0, -10])
// true
function monotonic(l){

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

function test() {
  let candidate = monotonic;
  assert.deepEqual(candidate([1, 2, 4, 10]),true);
  assert.deepEqual(candidate([1, 2, 4, 20]),true);
  assert.deepEqual(candidate([1, 20, 4, 10]),false);
  assert.deepEqual(candidate([4, 1, 0, -10]),true);
  assert.deepEqual(candidate([4, 1, 1, 0]),true);
  assert.deepEqual(candidate([1, 2, 3, 2, 5, 60]),false);
  assert.deepEqual(candidate([1, 2, 3, 4, 5, 60]),true);
  assert.deepEqual(candidate([9, 9, 9, 9]),true);
}

test();


Prompt:
//Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return undefined in case the input array is empty.
// >>> longest([])
// undefined
// >>> longest(["a", "b", "c"])
// "a"
// >>> longest(["a", "bb", "ccc"])
// "ccc"
function longest(strings){

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

function test() {
  let candidate = longest;
  assert.deepEqual(candidate([]),undefined);
  assert.deepEqual(candidate(["x", "y", "z"]),"x");
  assert.deepEqual(candidate(["x", "yyy", "zzzz", "www", "kkkk", "abc"]),"zzzz");
}

test();


Prompt:
//Return true if all numbers in the array l are below threshold t.
// >>> below_threshold([1, 2, 4, 10], 100)
// true
// >>> below_threshold([1, 20, 4, 10], 5)
// false
function below_threshold(l, t){

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

function test() {
  let candidate = below_threshold;
  assert.deepEqual(candidate([1, 2, 4, 10], 100),true);
  assert.deepEqual(candidate([1, 20, 4, 10], 5),false);
  assert.deepEqual(candidate([1, 20, 4, 10], 21),true);
  assert.deepEqual(candidate([1, 20, 4, 10], 22),true);
  assert.deepEqual(candidate([1, 8, 4, 10], 11),true);
  assert.deepEqual(candidate([1, 8, 4, 10], 10),false);
}

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:
//Return only positive numbers in the array.
// >>> get_positive([-1, 2, -4, 5, 6])
// [2, 5, 6]
// >>> get_positive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])
// [5, 3, 2, 3, 9, 123, 1]
function get_positive(l){

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

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

test();


Prompt:
//This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// >>> sort_third([1, 2, 3])
// [1, 2, 3]
// >>> sort_third([5, 6, 3, 4, 8, 9, 2])
// [2, 6, 3, 4, 8, 9, 5]
function sort_third(l){


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 length of a side and high return area for a triangle.
// >>> triangle_area(5, 3)
// 7.5
function triangle_area(a, h){

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

function test() {
  let candidate = triangle_area;
  assert.deepEqual(candidate(5, 3),7.5);
  assert.deepEqual(candidate(2, 2),2.0);
  assert.deepEqual(candidate(10, 8),40.0);
}

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:
//For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// >>> mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])
// 1.0
function mean_absolute_deviation(numbers){

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

function test() {
  let candidate = mean_absolute_deviation;
  assert.deepEqual(candidate([1.0, 2.0]),0.5);
  assert.deepEqual(candidate([1.0, 2.0, 3.0, 4.0]),1.0);
  assert.deepEqual(candidate([1.0, 2.0, 3.0, 4.0, 5.0]),1.2);
}

test();


Prompt:
//Return sorted unique common elements for two arrays.
// >>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121])
// [1, 5, 653]
// >>> common([5, 3, 2, 8], [3, 2])
// [2, 3]
function common(l1, l2){

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

function test() {
  let candidate = common;
  assert.deepEqual(candidate([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]),[1, 5, 653]);
  assert.deepEqual(candidate([5, 3, 2, 8], [3, 2]),[2, 3]);
  assert.deepEqual(candidate([4, 3, 2, 8], [3, 2, 4]),[2, 3, 4]);
  assert.deepEqual(candidate([4, 3, 2, 8], []),[]);
}

test();


Prompt:
//Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// >>> int_to_mini_roman(19)
// "xix"
// >>> int_to_mini_roman(152)
// "clii"
// >>> int_to_mini_roman(426)
// "cdxxvi"
function int_to_mini_roman(number){

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

function test() {
  let candidate = int_to_mini_roman;
  assert.deepEqual(candidate(19),"xix");
  assert.deepEqual(candidate(152),"clii");
  assert.deepEqual(candidate(251),"ccli");
  assert.deepEqual(candidate(426),"cdxxvi");
  assert.deepEqual(candidate(500),"d");
  assert.deepEqual(candidate(1),"i");
  assert.deepEqual(candidate(4),"iv");
  assert.deepEqual(candidate(43),"xliii");
  assert.deepEqual(candidate(90),"xc");
  assert.deepEqual(candidate(94),"xciv");
  assert.deepEqual(candidate(532),"dxxxii");
  assert.deepEqual(candidate(900),"cm");
  assert.deepEqual(candidate(994),"cmxciv");
  assert.deepEqual(candidate(1000),"m");
}

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:
//Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return an array containing the result string and true/false for the check.
// Example
// >>> reverse_delete("abcde", "ae")
// ["bcd", false]
// >>> reverse_delete("abcdef", "b")
// ["acdef", false]
// >>> reverse_delete("abcdedcba", "ab")
// ["cdedc", true]
function reverse_delete(s, c){

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

function test() {
  let candidate = reverse_delete;
  assert.deepEqual(candidate("abcde", "ae"),["bcd", false]);
  assert.deepEqual(candidate("abcdef", "b"),["acdef", false]);
  assert.deepEqual(candidate("abcdedcba", "ab"),["cdedc", true]);
  assert.deepEqual(candidate("dwik", "w"),["dik", false]);
  assert.deepEqual(candidate("a", "a"),["", true]);
  assert.deepEqual(candidate("abcdedcba", ""),["abcdedcba", true]);
  assert.deepEqual(candidate("abcdedcba", "v"),["abcdedcba", true]);
  assert.deepEqual(candidate("vabba", "v"),["abba", true]);
  assert.deepEqual(candidate("mamma", "mia"),["", true]);
}

test();


Prompt:
//Return a greatest common divisor of two integers a and b
// >>> greatest_common_divisor(3, 5)
// 1
// >>> greatest_common_divisor(25, 15)
// 5
function greatest_common_divisor(a, b){

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

function test() {
  let candidate = greatest_common_divisor;
  assert.deepEqual(candidate(3, 7),1);
  assert.deepEqual(candidate(10, 15),5);
  assert.deepEqual(candidate(49, 14),7);
  assert.deepEqual(candidate(144, 60),12);
}

test();


Prompt:
//Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// >>> split_words("Hello world!")
// ["Hello", "world!"]
// >>> split_words("Hello,world!")
// ["Hello", "world!"]
// >>> split_words("abcdef")
// 3
function split_words(txt){

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

function test() {
  let candidate = split_words;
  assert.deepEqual(candidate("Hello world!"),["Hello", "world!"]);
  assert.deepEqual(candidate("Hello,world!"),["Hello", "world!"]);
  assert.deepEqual(candidate("Hello world,!"),["Hello", "world,!"]);
  assert.deepEqual(candidate("Hello,Hello,world !"),["Hello,Hello,world", "!"]);
  assert.deepEqual(candidate("abcdef"),3);
  assert.deepEqual(candidate("aaabb"),2);
  assert.deepEqual(candidate("aaaBb"),1);
  assert.deepEqual(candidate(""),0);
}

test();


Prompt:
//In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// >>> sort_array([1, 5, 2, 3, 4])
// [1, 2, 3, 4, 5]
// >>> sort_array([-2, -3, -4, -5, -6])
// [-6, -5, -4, -3, -2]
// >>> sort_array([1, 0, 2, 3, 4])
// [0, 1, 2, 3, 4]
function sort_array(arr){


Prompt:
//Concatenate array of strings into a single string
// >>> concatenate([])
// ""
// >>> concatenate(["a", "b", "c"])
// "abc"
function concatenate(strings){

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

function test() {
  let candidate = concatenate;
  assert.deepEqual(candidate([]),"");
  assert.deepEqual(candidate(["x", "y", "z"]),"xyz");
  assert.deepEqual(candidate(["x", "y", "z", "w", "k"]),"xyzwk");
}

test();


Prompt:
//Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// >>> list_sort(["aa", "a", "aaa"])
// ["aa"]
// >>> list_sort(["ab", "a", "aaa", "cd"])
// ["ab", "cd"]
function sorted_list_sum(lst){

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

function test() {
  let candidate = sorted_list_sum;
  assert.deepEqual(candidate(["aa", "a", "aaa"]),["aa"]);
  assert.deepEqual(candidate(["school", "AI", "asdf", "b"]),["AI", "asdf", "school"]);
  assert.deepEqual(candidate(["d", "b", "c", "a"]),[]);
  assert.deepEqual(candidate(["d", "dcba", "abcd", "a"]),["abcd", "dcba"]);
  assert.deepEqual(candidate(["AI", "ai", "au"]),["AI", "ai", "au"]);
  assert.deepEqual(candidate(["a", "b", "b", "c", "c", "a"]),[]);
  assert.deepEqual(candidate(["aaaa", "bbbb", "dd", "cc"]),["cc", "dd", "aaaa", "bbbb"]);
}

test();


Prompt:
//Filter an input array 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:
//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:
//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:
//Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// >>> find_max(["name", "of", "string"])
// "string"
// >>> find_max(["name", "enam", "game"])
// "enam"
// >>> find_max(["aaaaaaa", "bb", "cc"])
// "aaaaaaa"
function find_max(words){

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

function test() {
  let candidate = find_max;
  assert.deepEqual(candidate(["name", "of", "string"]),"string");
  assert.deepEqual(candidate(["name", "enam", "game"]),"enam");
  assert.deepEqual(candidate(["aaaaaaa", "bb", "cc"]),"aaaaaaa");
  assert.deepEqual(candidate(["abc", "cba"]),"abc");
  assert.deepEqual(candidate(["play", "this", "game", "of", "footbott"]),"footbott");
  assert.deepEqual(candidate(["we", "are", "gonna", "rock"]),"gonna");
  assert.deepEqual(candidate(["we", "are", "a", "mad", "nation"]),"nation");
  assert.deepEqual(candidate(["this", "is", "a", "prrk"]),"this");
  assert.deepEqual(candidate(["b"]),"b");
  assert.deepEqual(candidate(["play", "play", "play"]),"play");
}

test();


Prompt:
//Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return undefined.
// >>> string_to_md5("Hello world")
// "3e25960a79dbc69b674cd4ec67a72c62"
function string_to_md5(text){

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

function test() {
  let candidate = string_to_md5;
  assert.deepEqual(candidate("Hello world"),"3e25960a79dbc69b674cd4ec67a72c62");
  assert.deepEqual(candidate(""),undefined);
  assert.deepEqual(candidate("A B C"),"0ef78513b0cb8cef12743f5aeb35f888");
  assert.deepEqual(candidate("password"),"5f4dcc3b5aa765d61d8327deb882cf99");
}

test();


Prompt:
//Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// >>> change_base(8, 3)
// "22"
// >>> change_base(8, 2)
// "1000"
// >>> change_base(7, 2)
// "111"
function change_base(x, base){

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

function test() {
  let candidate = change_base;
  assert.deepEqual(candidate(8, 3),"22");
  assert.deepEqual(candidate(9, 3),"100");
  assert.deepEqual(candidate(234, 2),"11101010");
  assert.deepEqual(candidate(16, 2),"10000");
  assert.deepEqual(candidate(8, 2),"1000");
  assert.deepEqual(candidate(7, 2),"111");
  assert.deepEqual(candidate(2, 3),"2");
  assert.deepEqual(candidate(3, 4),"3");
  assert.deepEqual(candidate(4, 5),"4");
  assert.deepEqual(candidate(5, 6),"5");
  assert.deepEqual(candidate(6, 7),"6");
  assert.deepEqual(candidate(7, 8),"7");
}

test();


Prompt:
//Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// >>> right_angle_triangle(3, 4, 5)
// true
// >>> right_angle_triangle(1, 2, 3)
// false
function right_angle_triangle(a, b, c){

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

function test() {
  let candidate = right_angle_triangle;
  assert.deepEqual(candidate(3, 4, 5),true);
  assert.deepEqual(candidate(1, 2, 3),false);
  assert.deepEqual(candidate(10, 6, 8),true);
  assert.deepEqual(candidate(2, 2, 2),false);
  assert.deepEqual(candidate(7, 24, 25),true);
  assert.deepEqual(candidate(10, 5, 7),false);
  assert.deepEqual(candidate(5, 12, 13),true);
  assert.deepEqual(candidate(15, 8, 17),true);
  assert.deepEqual(candidate(48, 55, 73),true);
  assert.deepEqual(candidate(1, 1, 1),false);
  assert.deepEqual(candidate(2, 2, 10),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 an array of GPAs for some students and you have to write
// a function that can output an array 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:
//Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// >>> intersperse([], 4)
// []
// >>> intersperse([1, 2, 3], 4)
// [1, 4, 2, 4, 3]
function intersperse(numbers, delimeter){

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

function test() {
  let candidate = intersperse;
  assert.deepEqual(candidate([], 7),[]);
  assert.deepEqual(candidate([5, 6, 3, 2], 8),[5, 8, 6, 8, 3, 8, 2]);
  assert.deepEqual(candidate([2, 2, 2], 2),[2, 2, 2, 2, 2]);
}

test();


Prompt:
//Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// >>> specialFilter([15, -73, 14, -15])
// 1
// >>> specialFilter([33, -2, -3, 45, 21, 109])
// 2
function specialFilter(nums){

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

function test() {
  let candidate = specialFilter;
  assert.deepEqual(candidate([5, -2, 1, -5]),0);
  assert.deepEqual(candidate([15, -73, 14, -15]),1);
  assert.deepEqual(candidate([33, -2, -3, 45, 21, 109]),2);
  assert.deepEqual(candidate([43, -12, 93, 125, 121, 109]),4);
  assert.deepEqual(candidate([71, -2, -33, 75, 21, 19]),3);
  assert.deepEqual(candidate([1]),0);
  assert.deepEqual(candidate([]),0);
}

test();


Prompt:
//sum_to_n is a function that sums numbers from 1 to n.
// >>> sum_to_n(30)
// 465
// >>> sum_to_n(100)
// 5050
// >>> sum_to_n(5)
// 15
// >>> sum_to_n(10)
// 55
// >>> sum_to_n(1)
// 1
function sum_to_n(n){

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

function test() {
  let candidate = sum_to_n;
  assert.deepEqual(candidate(1),1);
  assert.deepEqual(candidate(6),21);
  assert.deepEqual(candidate(11),66);
  assert.deepEqual(candidate(30),465);
  assert.deepEqual(candidate(100),5050);
}

test();


Prompt:
//From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// >>> remove_duplicates([1, 2, 3, 2, 4])
// [1, 3, 4]
function remove_duplicates(numbers){

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

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

test();


Prompt:
//Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// >>> generate_integers(2, 8)
// [2, 4, 6, 8]
// >>> generate_integers(8, 2)
// [2, 4, 6, 8]
// >>> generate_integers(10, 14)
// []
function generate_integers(a, b){

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

function test() {
  let candidate = generate_integers;
  assert.deepEqual(candidate(2, 10),[2, 4, 6, 8]);
  assert.deepEqual(candidate(10, 2),[2, 4, 6, 8]);
  assert.deepEqual(candidate(132, 2),[2, 4, 6, 8]);
  assert.deepEqual(candidate(17, 89),[]);
}

test();


Prompt:
//From a given array of integers, generate an array 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();


Prompt:
//You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// >>> below_zero([1, 2, 3])
// false
// >>> below_zero([1, 2, -4, 5])
// true
function below_zero(operations){

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

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

test();


Prompt:
//You are given a non-empty array 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 array.
// 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:
//brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// >>> correct_bracketing("(")
// false
// >>> correct_bracketing("()")
// true
// >>> correct_bracketing("(()())")
// true
// >>> correct_bracketing(")(()")
// false
function correct_bracketing(brackets){

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

function test() {
  let candidate = correct_bracketing;
  assert.deepEqual(candidate("()"),true);
  assert.deepEqual(candidate("(()())"),true);
  assert.deepEqual(candidate("()()(()())()"),true);
  assert.deepEqual(candidate("()()((()()())())(()()(()))"),true);
  assert.deepEqual(candidate("((()())))"),false);
  assert.deepEqual(candidate(")(()"),false);
  assert.deepEqual(candidate("("),false);
  assert.deepEqual(candidate("(((("),false);
  assert.deepEqual(candidate(")"),false);
  assert.deepEqual(candidate("(()"),false);
  assert.deepEqual(candidate("()()(()())())(()"),false);
  assert.deepEqual(candidate("()()(()())()))()"),false);
}

test();


Prompt:
//This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// >>> sort_even([1, 2, 3])
// [1, 2, 3]
// >>> sort_even([5, 6, 3, 4])
// [3, 6, 5, 4]
function sort_even(l){


Prompt:
//Check if two words have the same characters.
// >>> same_chars("eabcdzzzz", "dddzzzzzzzddeddabc")
// true
// >>> same_chars("abcd", "dddddddabc")
// true
// >>> same_chars("dddddddabc", "abcd")
// true
// >>> same_chars("eabcd", "dddddddabc")
// false
// >>> same_chars("abcd", "dddddddabce")
// false
// >>> same_chars("eabcdzzzz", "dddzzzzzzzddddabc")
// false
function same_chars(s0, s1){

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

function test() {
  let candidate = same_chars;
  assert.deepEqual(candidate("eabcdzzzz", "dddzzzzzzzddeddabc"),true);
  assert.deepEqual(candidate("abcd", "dddddddabc"),true);
  assert.deepEqual(candidate("dddddddabc", "abcd"),true);
  assert.deepEqual(candidate("eabcd", "dddddddabc"),false);
  assert.deepEqual(candidate("abcd", "dddddddabcf"),false);
  assert.deepEqual(candidate("eabcdzzzz", "dddzzzzzzzddddabc"),false);
  assert.deepEqual(candidate("aabb", "aaccc"),false);
}

test();


Prompt:
//brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// >>> correct_bracketing("<")
// false
// >>> correct_bracketing("<>")
// true
// >>> correct_bracketing("<<><>>")
// true
// >>> correct_bracketing("><<>")
// false
function correct_bracketing(brackets){

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

function test() {
  let candidate = correct_bracketing;
  assert.deepEqual(candidate("<>"),true);
  assert.deepEqual(candidate("<<><>>"),true);
  assert.deepEqual(candidate("<><><<><>><>"),true);
  assert.deepEqual(candidate("<><><<<><><>><>><<><><<>>>"),true);
  assert.deepEqual(candidate("<<<><>>>>"),false);
  assert.deepEqual(candidate("><<>"),false);
  assert.deepEqual(candidate("<"),false);
  assert.deepEqual(candidate("<<<<"),false);
  assert.deepEqual(candidate(">"),false);
  assert.deepEqual(candidate("<<>"),false);
  assert.deepEqual(candidate("<><><<><>><>><<>"),false);
  assert.deepEqual(candidate("<><><<><>><>>><>"),false);
}

test();