function bonusTime(salary, bonus) {
if (bonus == true){
salary *= 10;
return "\u00A3"+salary;
}else{
return "\u00A3"+salary;
}
}
function generateRange(min, max, step){
let array = [];
for (let i = min;i <=max; i+=step){
array.push(i);
}
return array;
}
function hoopCount (n) {
if (n >= 10){
return "Great, now move on to tricks";
} else {
return "Keep at it until you get it";
}
}
function apple(x){
return (Math.pow(x,2) > 1000) ? 'It\'s hotter than the sun!!' : 'Help yourself to a honeycomb Yorkie for the glovebox.';
}
function countPositivesSumNegatives(arr) {
if (arr === null || arr.length === 0) return [];
let countPos = 0, summNeg = 0;
for (let i = 0;i < arr.length; i++){
if (arr[i] > 0){
countPos++;
} else {
summNeg +=arr[i];
}
}
return [countPos,summNeg];
}
function howMuchILoveYou(n) {
const fl = ['I love you','a little','a lot','passionately','madly','not at all'];
return fl[(n - 1) % 6];
}
function DNAStrand(dna){
let a = '';
for (let i = 0; i < dna.length; i++){
if (dna[i] === 'A') a+= 'T';
if (dna[i] === 'T') a+= 'A';
if (dna[i] === 'G') a+= 'C';
if (dna[i] === 'C') a+= 'G';
}
return a;
}
function sumOfDifferences(arr) {
const sorted = arr.sort((a,b) => b-a);
let summ = 0;
for (let i = 0;i < sorted.length - 1; i++){
summ += sorted[i] - sorted[i + 1];
}
return summ;
}
function drawStairs(n) {
let s = '';
for (let i = 1; i<=n ; i++){
s += i === n ? 'I' :'I\n' + ' '.repeat(i)
}
return s;
}
function warnTheSheep(q) {
const l = q.length;
const w = q.indexOf('wolf');
if (l === w + 1) return "Pls go away and stop eating my sheep";
return `Oi! Sheep number ${l - 1 - w}! You are about to be eaten by a wolf!`;
}
function arraySum(arr) {
let a = arr.toString().split(',');
let sum = 0;
for (let i = 0;i < a.length; i++){
sum+= Number.isNaN(Number (a[i])) ? 0 : Number (a[i]);
}
return sum;
}
function distinct(a) {
let b ={};
let res = [];
for (let i = 0; i < a.length; i++){
if(!b[a[i]]){
res.push(a[i]);
b[a[i]] = 1;
}
}
return res;
}
function spongeMeme(sen) {
let bob = '';
for (let i = 0; i < sen.length; i++){
if (i % 2 !== 0){
bob += sen[i].toLowerCase();
} else {
bob += sen[i].toUpperCase();
}
}
return bob;
}
function squareArea(A){
return Math.round(Math.pow( (A / (2 * Math.PI)) * 4 , 2 ) * 100 ) / 100;
}
function bmi(weight, height) {
let bmi = weight / (height ** 2);
console.log(bmi);
if (bmi <= 18.5){
return "Underweight";
} else if (bmi <= 25.0 ){
return "Normal";
} else if (bmi <= 30.0 ){
return "Overweight";
} else {
return "Obese";
}
}
function getRealFloor(n) {
console.log(n)
if (n <= 0){
return n;
} else if (n >= 1 && n < 14 ){
return n - 1;
}else {
return n - 2;
}
}
function getAges(s,d){
console.log(s,d)
if (s < 0 || d < 0 || d > s){
return null;
} else {
return [(s + d) / 2 , ((s + d) / 2) - d] ;
}
}
function howManyDalmatians(number){
var dogs = ["Hardly any", "More than a handful!", "Woah that's a lot of dogs!", "101 DALMATIANS!!!"];
var respond = (number <= 10) ? dogs[0] : (number <= 50) ? dogs[1] : (number === 101)? dogs[3] : dogs[2];
return respond;
}
function oddOrEven(array) {
let sum = 0;
for (let i = 0; i < array.length;i++){
sum += array[i];
}
return sum % 2 ? 'odd' : 'even';
}
function differenceOfSquares(n){
let sum = 0;
let sumSquares = 0;
while (n > 0){
sum += n;
sumSquares += Math.pow(n , 2);
n--;
}
let squareSum = Math.pow(sum, 2)
return squareSum - sumSquares;
}
function largestPower(n){
let k = 0;
while (Math.pow(3,k) < n){
k++;
}
return k-1;
}
function SeriesSum(n){
let result = 1;
let sum = 1;
if (n === 0 || n ===1 ){
return n.toFixed(2);
} else {
for (i = 1; i < n; i++){
sum +=3;
result +=(1/sum)
}
}
return result.toFixed(2)
}
function getSum( a,b ){
console.log(a, b)
let sum = 0;
if (a < b){
for (let i = a; i <= b; i++){
sum += i;
}
} else {
for (let i = b; i <= a; i++){
sum += i;
}
}
return sum;
}
function numberToPower(n, p){
console.log(n,p)
let iGotPower = 1;
let number = p;
if (p == 0){
return iGotPower;
} else {
do {
iGotPower *= n;
number--;
}
while (number > 0);
}
return iGotPower;
}
var FilterString = function(value) {
let string = "";
for (i = 0;i < value.length; i++){
if (isNaN(value[i])){
continue;
} else {
string += value[i];
}
}
return +string;
}
function squares(x, n) {
let arr = [];
let mult = x;
for (let i = 0;i < n; i++ ){
arr[i] = mult;
mult *= mult;
}
return arr;
}
function squareDigits(num){
let str = num + "";
let strNum = "";
for (let i = 0 ; i < str.length; i++){
strNum += Math.pow(str[i], 2);
}
return +strNum;
}
function findNextSquare(sq) {
let notPerfect = -1;
if (Math.sqrt(sq) % 1 == 0){
return Math.pow(Math.sqrt(sq) + 1, 2);
} else {
return notPerfect;
}
}
function squaresNeeded(g){
if (g == 0){
return 0;
} else {
return 1 + Math.trunc(Math.log2(g));
}
}
function race(v1, v2, g) {
let hours;
let distance;
let minutes;
let seconds;
if (v1 >= v2){
return null;
} else {
distance = (v2 * g) / (v2 -v1);
}
hours = distance / v2
minutes = (hours - Math.trunc(hours)) * 60
seconds = ((minutes - Math.trunc(minutes))).toFixed(3) * 60
return [Math.trunc(hours), Math.trunc(minutes), Math.trunc(seconds)]
}
function pipeFix(numbers){
let array = [];
for (let i = Math.min(...numbers) ;i <= Math.max(...numbers); i++){
array.push(i);
}
return array;
}
function excludingVatPrice(price){
let originalPrice = price - ((price * 15) / 115);
if (price == null){
return -1;
} else {
return +originalPrice.toFixed(2);
}
}
const arrCheck = value =>{
if (value.length == 0) return true;
for (let i = 0; i < value.length; i++){
if ({}.toString.call(value[i]) != "[object Array]" ){
return false;
} else if ({}.toString.call(value[value.length - 1]) == "[object Array]" ){
return true;
}
}
}
function findNeedle(haystack) {
let position = 0;
for (let i = 0; i < haystack.length ; i++){
if (haystack[i] === 'needle' ){
position = i;
break;
}
}
return `found the needle at position ${position}`;
}
function positiveSum(arr) {
let sumPositive = 0;
for (let i = 0; i < arr.length; i++){
if (arr[i] > 0){
sumPositive += arr[i];
}
}
return sumPositive;
}
function divCon(x){
let sumNumbers = 0;
let sumStrings = 0;
for (let i = 0; i < x.length; i++){
if (typeof x[i] == 'string'){
sumStrings += +x[i];
} else {
sumNumbers += x[i];
}
}
return sumNumbers - sumStrings;
}
function cubeOdd(arr) {
let sum = 0;
for (let i = 0; i < arr.length; i ++){
if (typeof arr[i] == 'string'){
return undefined;
} else if (arr[i] % 2 !== 0) {
sum += Math.pow(arr[i], 3);
}
}
return sum;
}
function sumTwoSmallestNumbers(numbers) {
let minOne = Math.min(...numbers);
numbers.splice(numbers.indexOf(Math.min(...numbers)),1);
let minTwo = Math.min(...numbers);
return minOne + minTwo;
}
function removeSmallest(numbers) {
let myArray = [...numbers];
myArray.splice(myArray.indexOf(Math.min(...myArray)),1)
console.log(numbers);
return myArray;
}
function sumArray(array) {
let sum = 0;
if (array == null || array.length < 3 ){
return 0;
} else {
array.splice(array.indexOf(Math.min(...array)),1);
array.splice(array.indexOf(Math.max(...array)),1);
for (let i = 0 ; i < array.length;i++){
sum += array[i];
}
}
return sum;
}
function divisors(integer) {
let count = 0;
let arr = [];
console.log(integer)
for (let i = 2; i < integer; i++){
if (integer % i == 0){
arr.push(i);
count++;
}
}
if (count == 0){
return `${integer} is prime`
} else {
return arr;
}
}
function getEvenNumbers(numbersArray){
return numbersArray.filter(function(numbers){
return numbers % 2 == 0;
});
}
function countWins(winnerList, country) {
let myList = winnerList.filter(el => el.country == country);
return myList.length;
}
function filterEvenLengthWords(words) {
return words.filter(word => word.length % 2 == 0);
}
function findChildren(santasList, children) {
let myList = [];
for (let i = 0; i < children.length; i++){
if (santasList.includes(children[i])){
myList.push(children[i]);
}
}
return myList.filter((el,i) => myList.indexOf(el) === i).sort();
}
function array_diff(a, b) {
console.log(a, b)
return a.filter( ( el ) => !b.includes( el ) );
}
function duplicates(arr) {
return arr.filter((el, i) => i !== arr.indexOf(el) && i === arr.lastIndexOf(el));
}
function unique(arr) {
return arr.filter((el, i) => i === arr.indexOf(el));
}
function twoOldestAges(ages){
ages.sort((a, b) => a - b);
return [ages[ages.length - 2], ages[ages.length - 1] ];
}
function buildString(...template){
return `I like ${template.join(', ')}!`;
}
function validatePIN (pin) {
for ( let i = 0;i < pin.length; i++){
if (pin.codePointAt(i) > 47 && pin.codePointAt(i) < 58 ){
continue;
} else {
return false;
}
}
if (pin.length == 4 || pin.length == 6){
return true;
} else {
return false;
}
}
function switcher(x){
let string = '';
let letters = ["z", "y", "x", "w", "v", "u", "t", "s", "r", "q","p", "o", "n", "m", "l", "k", "j", "i", "h", "g","f", "e", "d", "c", "b", "a","!","?"," "];
for (let i = 0; i < x.length; i++){
string += letters[+x[i]-1];
}
return string;
}
var uniqueInOrder=function(iterable){
let myArray = [];
for (let i = 0;i < iterable.length;i++){
if (myArray[myArray.length -1] !== iterable[i] ){
myArray.push(iterable[i]);
}
}
console.log(iterable,myArray)
return myArray;
}
function testit(s){
if (s.length == 0) return s;
let testSomething = s.split(" ")
for (let i = 0; i < testSomething.length ;i++){
testSomething[i] = testSomething[i].slice(0,-1) + testSomething[i][testSomething[i].length -1].toUpperCase();
}
return testSomething.join(" ");
}
function accum(s) {
let arr = s.toLowerCase().split("");
for (let i = 0; i < arr.length; i++){
arr[i] = arr[i].toUpperCase() + arr[i].repeat(i);
}
return arr.join("-");
}
var capitals = function (word) {
let arr = [];
for (let i = 0;i < word.length;i++){
if (word[i] === word[i].toUpperCase()){
arr.push(word.indexOf(word[i]))
}
}
return arr;
};
function dontGiveMeFive(start, end) {
var noFive = 0;
for (i = start; i <= end; i++) {
if (i.toString().includes("5")){
continue;
} else {
noFive++;
}
}
return noFive;
}
function solution(str, ending){
return str.endsWith(ending);
}
function tailSwap(arr) {
let myArr = [];
myArr[0] = arr[0].slice(0,arr[0].indexOf(':')) + arr[1].slice(arr[1].indexOf(':'));
myArr[1] = arr[1].slice(0,arr[1].indexOf(':')) + arr[0].slice(arr[0].indexOf(':'));
return myArr;
}
function maskify(cc) {
if (cc.length < 5) return cc;
return "#".repeat(cc.length -4) + cc.slice(-4);
}
function findLongest(str){
var spl = str.split(" ");
var longest = 0;
for (var i = 0; i < spl.length; i++){
if (spl[i].length > longest) {
longest = spl[i].length;
}
}
return longest;
}
function descendingOrder(n){
let m = n.toString().split("").sort((a,b) => b - a).join("");
return +m;
}
function highAndLow(numbers){
let num = numbers.split(" ").sort((a,b) => b - a);
return num[0] + " " + num[num.length -1]
}
function determineTime(durations){
if (durations.length == 0) return true;
let sec = 0;
let min = 0;
let hours = 0;
for (let i = 0; i < durations.length;i++){
sec += + (durations[i][6] + durations[i][7]);
min += + (durations[i][3] + durations[i][4]);
hours += + (durations[i][0] + durations[i][1]);
}
min += Math.trunc(sec / 60);
hours += Math.trunc(sec / 60);
return hours < 24;
}
function digits(num){
let arr = num.toString().split("");
let myArr = [];
for (let i = 0; i < arr.length ; i++){
for(let k = 1+i; k < arr.length; k++){
myArr.push(+arr[i]+ +arr[k]);
}
}
return myArr;
}
function duckDuckGoose(players, goose) {
if (goose <= players.length) return players[goose - 1].name;
if (goose % players.length == 0){
return players[players.length - 1].name;
} else {
return players[(goose % players.length) - 1].name;
}
}
function greet(language) {
let greeting = {
english: 'Welcome',
czech: 'Vitejte',
danish: 'Velkomst',
dutch: 'Welkom',
estonian: 'Tere tulemast',
finnish: 'Tervetuloa',
flemish: 'Welgekomen',
french: 'Bienvenue',
german: 'Willkommen',
irish: 'Failte',
italian: 'Benvenuto',
latvian: 'Gaidits',
lithuanian: 'Laukiamas',
polish: 'Witamy',
spanish: 'Bienvenido',
swedish: 'Valkommen',
welsh: 'Croeso',
}
return language in greeting ? greeting[language] : greeting.english;
}
function arithmetic(a, b, operator){
switch(operator) {
case 'add':
return a + b;
break;
case 'subtract':
return a - b;
break;
case 'multiply':
return a * b;
break;
case 'divide':
return a / b;
break;
}
}
let makeBackronym = function(string){
let arr = string.toUpperCase().split("");
let phrase = "";
for (let i = 0; i < arr.length ; i++){
if (i == arr.length - 1){
phrase += dict[arr[i]];
} else {
phrase += dict[arr[i]] + " ";
}
}
return phrase;
};
function checkThreeAndTwo(array) {
let countA = 0;
let countB = 0;
let countC = 0;
for ( let i = 0; i < array.length; i++){
if ( array[i] == 'a') countA++;
if ( array[i] == 'b') countB++;
if ( array[i] == 'c') countC++;
}
return ((countA == 3 || countB == 3 || countC == 3) && (countA == 2 || countB == 2 || countC == 2));
}
function match(candidate, job) {
if (candidate.minSalary === undefined || job.maxSalary === undefined ) throw "Error";
return candidate.minSalary - candidate.minSalary / 10 <= job.maxSalary;
}
for ( let i = 0; i < questions.length ; i++){
questions[i].usersAnswer = null;
}
function numObj(s){
let obj = [];
for( let i = 0; i < s.length; i++){
obj[i] = {};
obj[i][s[i]] = String.fromCharCode(s[i]);
}
return obj;
}
function countLanguages(list) {
let answer = {};
for (i = 0; i< list.length; i++){
if (answer[list[i].language]) {
answer[list[i].language]++;
} else {
answer[list[i].language] = 1;
}
}
return answer;
}
function outed(meet, boss){
let sumMood = 0;
let count = 0;
for (let e in meet){
if(e === boss ){
sumMood += meet[e] * 2
count++
} else {
sumMood += meet[e];
count++;
}
}
return (sumMood / count) <= 5 ? 'Get Out Now!' : 'Nice Work Champ!';
}
function daysRepresented(trips){
let days = [];
for ( let i = 0; i < trips.length; i++){
for (let k = trips[i][0]; k <= trips[i][1]; k++){
if (!days.includes(k)){
days.push(k);
}
}
}
return days.length;
}
function nameScore(name){
let score = {};
score[name] = 0
let arr = name.toUpperCase().split("");
for (let i = 0; i < arr.length; i++){
for ( let key in alpha){
if (key.includes(arr[i])){
score[name] += alpha[key];
console.log(name)
}
}
}
return score;
}
function permuteAPalindrome (input) {
let countOdd = 0;
let arr = input.split("");
let obj = {};
for ( let i = 0; i < arr.length; i++ ){
if ( arr[i] in obj){
obj[arr[i]]++;
} else {
obj[arr[i]] = 1;
}
}
for (let key in obj){
if (obj[key] % 2 != 0){
countOdd++;
}
}
return countOdd <= 1;
}
function solve(st) {
let obj = {};
for (let i = 0; i < st.length; i++) {
obj[st[i]] = st.lastIndexOf(st[i]) - st.indexOf(st[i]);
}
let arr = [];
for (let key in obj){
arr.push(obj[key]);
}
let value = Math.max(...arr);
let arrWithEqualValue = [];
for (let key in obj){
if (obj[key] === value) arrWithEqualValue.push(key);
}
arrWithEqualValue.sort();
return arrWithEqualValue[0];
}
function boredom(staff){
let staffScores = {
accounts : 1,
finance: 2,
canteen : 10,
regulation : 3,
trading : 6,
change : 6,
IS : 8,
retail : 5,
cleaning : 4,
'pissing about' : 25,
};
let score = 0;
for (let key in staffScores) {
for (let keys in staff){
if (key === staff[keys]) score += staffScores[key];
}
}
if (score <= 80) {
return 'kill me now';
} else if (score < 100 && score > 80) {
return 'i can handle this';
} else {
return 'party time!!';}
}
function likes(names) {
if (names.length == 0) return "no one likes this";
if (names.length == 1) return `${names[0]} likes this`;
if (names.length == 2) return `${names[0]} and ${names[1]} like this`;
if (names.length == 3) return `${names[0]}, ${names[1]} and ${names[2]} like this`;
if (names.length > 3) return `${names[0]}, ${names[1]} and ${names.length - 2} others like this`;
}
function validParentheses(str){
let a = 0;
for ( let i = 0; i < str.length ; i++){
if (str[i] === '(') a = a + 1;
else if (str[i] === ')') a = a - 1;
if (a < 0) return false;
}
return (a === 0);
}
function sentence(List) {
let arr = []
let str = "";
for (let i = 0; i < List.length; i++){
arr = arr.concat(Object.keys(List[i]))
}
arr.sort((a, b) => a-b)
for (let k = 0; k < List.length; k++){
for(let x = 0; x < List.length; x++){
if (arr[k] in List[x])
{ str += " " + List[x][arr[k]] }
}
}
return str.trim();
}
function getRectangleString(w, h) {
let rn = '\r\n';
let tb ='*'.repeat(w) + rn;
let center = (w > 1) ? ('*' + ' '.repeat(w - 2) + '*' + rn).repeat(h-2) : '';
return h > 1 ? (tb + center + tb) : tb.repeat(h);
}
function arraysSimilar(arr1, arr2) {
if(arr1.length !== arr2.length) return false;
arr1.sort();
arr2.sort();
for( let i = 0; i < arr1.length; i++){
if (arr1[i] !== arr2[i]) return false;
}
return true;
}
function avg(a){ return ( a.reduce((a, b) => a + b ) )/ a.length }
function getAverage(marks){
return Math.floor(marks.reduce((a,b) => a + b) / marks.length)
}
function findMissing(arr1, arr2) {
let index;
for(let i = 0; i < arr1.length; i++){
index = arr2.indexOf(arr1[i]);
if(index > -1){
arr2.splice(index,1);
} else {
return arr1[i];
}
}
}
function feast(beast, dish) {
return (beast[0] === dish[0] && beast[beast.length - 1] === dish[dish.length - 1] )
}
var cubeChecker = function(volume, side){
if (side === 0 || side < 0) return false;
return side ** 3 === volume;
};
function multiTable(n) {
let res = '';
for (let i = 1; i <= 10; i++){
res += `${ i } * ${ n } = ${ i * n }${i < 10 ? '\n' : ''}`;
}
return res;
}
function nthEven(n){
return n * 2 - 2;
}
function any(arr, fun){
return arr.some(fun);
}
function greet (name, owner) {
return name === owner ? 'Hello boss' : 'Hello guest';
}
function crap(x, bags, cap){
const str = x.toString();
if(str.includes('D')) return 'Dog!!'
const crapCount = str.split('@').length - 1;
return bags * cap >= crapCount ? 'Clean' : 'Cr@p';
}
function take(arr, n) {
return arr.slice(0, n);
}
function enough(cap, on, wait) {
return cap >= (on + wait) ? 0 : Math.abs(cap-on-wait);
}
function typeValidation(v, t) {
return typeof(v) === t;
}
function paperwork(n, m) {
return n < 0 || m < 0 ? 0 : n * m;
}
function past(h, m, s){
return h * 3600000 + m * 60000 + s * 1000;
}
function gooseFilter (birds) {
const geese = ["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"];
return birds.filter(el => !geese.includes(el));
};
function reverse(str){
if (str[0] === ' ') return '';
let newStr = str.split(' ');
for (let i = 0; i < newStr.length ; i++){
if (i % 2) newStr[i] = newStr[i].split('').reverse().join('');
}
return newStr.join(' ');
}
const rps = (p1, p2) => {
if (p1 === p2) return 'Draw!';
const getMsg = (n) => `Player ${n} won!`;
if(p1 === 'scissors' && p2 === 'paper' ) return getMsg(1);
if(p1 === 'paper' && p2 === 'scissors' ) return getMsg(2);
if(p1 === 'paper' && p2 === 'rock' ) return getMsg(1);
if(p1 === 'rock' && p2 === 'paper' ) return getMsg(2);
if(p1 === 'rock' && p2 === 'scissors' ) return getMsg(1);
if(p1 === 'scissors' && p2 === 'rock' ) return getMsg(2);
};
String.prototype.isUpperCase = function() {
return this.toUpperCase() == this;
}
function flattenAndSort(array) {
let myArray = [];
array.forEach( el => {
if(Number.isInteger(el)){
myArray.push(el);
} else if(Array.isArray(el) && el.length){
myArray = [...myArray, ...el];
}
});
return myArray.sort((a, b) => a-b);
}
function broken(x){
let res = '';
for ( let i = 0; i < x.length; i++){
res += x[i] === '0' ? '1' : '0';
}
return res;
}
function reverse(arr) {
let count = arr.length
for (let i = 0; i < count / 2; i++){
let el = arr[i]
arr[i] = arr[count - 1 - i]
arr[count - 1 - i] = el;
}
}
function loveLanguage(partner,weeks) {
let arr = [0 , 0 , 0 , 0 , 0];
for (let i = 0, index = 0; i < weeks * 7 ; i++){
index === 4 ? index = 0 : index++;
if (partner.response(LOVE_LANGUAGES[index]) == "positive"){
arr[index]++;
}
}
return LOVE_LANGUAGES[arr.indexOf(Math.max(...arr))];
}
function meeting(x){
return x.indexOf('O') < 0 ? 'None available!' : x.indexOf('O') ;
}
function averageString(str) {
if (str.length == 0) return "n/a";
let obj = {
"zero":0,
"one":1,
"two":2,
"three":3,
"four":4,
"five":5,
"six":6,
"seven":7,
"eight":8,
"nine":9
};
let newArr = [
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine"
];
let arr = str.split(' ');
let sum = 0;
for(let i = 0; i < arr.length; i++){
if(obj[arr[i]] !== undefined) {
sum +=obj[arr[i]]
} else {
return "n/a"
}
}
let avg = Math.floor(sum / arr.length);
return newArr[avg];
}
function openOrSenior(data){
return data.map((el, i) => el[0] >= 55 && el[1] > 7 ? 'Senior' : 'Open');
}
function gracefulTipping(bill) {
let billWithTips = Math.ceil(bill * 1.15);
if(bill < 10){
return billWithTips;
} else {
let zero = '0';
let divider = +('5' + zero.repeat(billWithTips.toString().length - 2 ));
if (billWithTips % divider === 0 ){
return billWithTips;
} else {
let num = Math.trunc(billWithTips / divider);
return (num + 1) * divider;
}
}
};
function meeting(x, need){
if (!need) return 'Game On';
let arr = [];
let ch = need;
for (let i = 0; i < x.length; i++){
if(ch > 0){
let c = x[i][1] - x[i][0].length;
arr.push(c > 0 ? (c > ch ? ch : c) : 0);
if (c > 0) ch -= c;
} else {
return arr
}
}
return ch <= 0 ? arr : 'Not enough!';
}
var orderedCount = function (text) {
return [...new Set(text)].map(letter => [letter, text.split(letter).length - 1]);
}
function getNiceNames(people){
let arr = []
for(let i = 0; i < people.length; i++){
if(people[i].wasNice){
arr.push(people[i].name)
}
}
return arr;
}
function getNaughtyNames(people){
let arr = []
for(let i = 0; i < people.length; i++){
if(!people[i].wasNice){
arr.push(people[i].name)
}
}
return arr;
}
function rowWeights(array){
let sumTeam1 = 0;
let sumTeam2 = 0;
for (let i = 0; i < array.length; i++){
if(i % 2 == 0){
sumTeam1 +=array[i]
} else {
sumTeam2 +=array[i]
}
}
return [sumTeam1, sumTeam2]
}
const gimme = function (arr) {
let min = Math.min(...arr);
let max = Math.max(...arr);
for(let i = 0; i < arr.length;i++){
if (arr[i] < max && arr[i] > min){
return i;
}
}
};
function isValidWalk(walk) {
if (walk.length != 10) return false;
let ns = 0;
let we = 0;
for (let i = 0; i < 10;i++){
if(walk[i] == 'n') ns++;
if(walk[i] == 's') ns--;
if(walk[i] == 'w') we++;
if(walk[i] == 'e') we--;
};
return ns == 0 && we == 0;
};
multiplicationTable = function(size) {
let arr = [];
for(let i = 1; i <= size; i++){
let newArr = [];
for(let j = 1; j <= size; j++){
newArr.push(i*j);
}
arr.push(newArr);
}
return arr;
}
function isSortedAndHow(array) {
let asc = [...array].sort((a,b) => a-b).join('');
let des = [...array].sort((a,b) => b-a).join('');
return asc == array.join('') ? 'yes, ascending' : des == array.join('') ? 'yes, descending' : 'no';
};
const moveZeros = function (arr) {
let newArr = [];
let totalZeros = 0;
for(let i = 0; i < arr.length; i++){
if(arr[i] !== 0) newArr.push(arr[i])
else totalZeros++;
};
for(let i = 0; i < totalZeros; i++){
newArr.push(0);
};
return newArr;
};
function rowSumOddNumbers(n) {
let firstElement = n * n - (n - 1);
let total = 0;
let count = 0;
while (count < n){
if(firstElement % 2 !== 0){
total += firstElement;
} else {
count++;
}
firstElement++;
};
return total;
};
function findStrangeValue() {
return NaN;
}
function getPlanetName(id){
let obj = {
1:'Mercury',
2:'Venus',
3:'Earth',
4:'Mars',
5:'Jupiter',
6:'Saturn',
7:'Uranus',
8:'Neptune'
}
return obj[id];
}
function rpsls(pl1,pl2){
let rules = [
"scissors paper",
"paper rock",
"rock lizard",
"lizard spock",
"spock scissors",
"scissors lizard",
"lizard paper",
"paper spock",
"spock rock",
"rock scissors"
]
if (rules.includes(pl1 + ' ' + pl2)) return 'Player 1 Won!';
else if(pl1 == pl2) return 'Draw!';
else return 'Player 2 Won!';
}
function capital(capitals){
let arr = [];
for (let i = 0; i < capitals.length; i++){
if (capitals[i].hasOwnProperty('state')) {
arr.push(`The capital of ${capitals[i]['state']} is ${capitals[i]['capital']}`);
}
if (capitals[i].hasOwnProperty('country')){
console.log(capitals.length)
arr.push(`The capital of ${capitals[i]['country']} is ${capitals[i]['capital']}`);
}
}
return arr;
}
function one(arr, fun){
let newArr = arr.filter(fun);
if(newArr.length > 1 || newArr.length == 0 ) return false;
return true;
}
function largestPairSum(numbers)
{
let ordered = numbers.sort((a,b) => b - a);
return ordered[0] + ordered[1];
}
function generateIntegers(m, n) {
let arr = [];
for(let i = m; m <= n; m++){
arr.push(m)
}
return arr;
}
function roundToNext5(n){
let num = n
while(num % 5 !== 0){
num++
}
return num;
}
function reject(array, predicate) {
return array.filter(el => !predicate(el))
}
function halvingSum(n) {
let sum = 0
for(let i = n; i > 0; i = Math.floor(i/2)){
sum +=i
}
return sum;
}
function modifiedSum(a, n) {
let sumPow = 0;
let sum = 0;
for(let i = 0; i < a.length; i++){
sumPow += Math.pow(a[i],n);
sum += a[i];
}
console.log()
return sumPow - sum;
}
function greet(name) {
if (typeof name == "string" && name.length) return `hello ${name}!`;
return null;
}
function completeSeries(arr) {
let myArr = [];
arr.sort((a,b) => b - a);
for(let i = 0; i <= arr[0]; i++){
if(arr.indexOf(arr[i]) !== arr.lastIndexOf(arr[i])) return [0]
myArr.push(i);
}
return myArr;
}
let greet = function(name) {
return "Hello " + name[0].toUpperCase() + name.toLowerCase().slice(1,name.length) + "!"
};
function solve(a,b){
let myStr = "";
for(let i = 0; i < a.length; i++){
if(!b.includes(a[i]) && typeof a[i] == "string") myStr += a[i];
}
for(let k = 0; k < b.length; k++){
if(!a.includes(b[k]) && typeof b[k] == "string") myStr += b[k];
}
return myStr;
};
function fix(paragraph){
if(paragraph.length == 0) return paragraph;
let fixed = paragraph[0].toUpperCase();
for(let i = 1; i < paragraph.length ; i++){
if(paragraph[i] == " " && paragraph[i - 1] == "."){
fixed += paragraph[i]
fixed += paragraph[i+1].toUpperCase();
i++
} else {
fixed += paragraph[i]
}
}
return fixed;
}
function capitalize(s){
let odd = "";
let even = ""
s.split("").map((el, i) => {
if(i % 2 == 0){
odd+=el.toUpperCase();
even+=el;
} else {
even+=el.toUpperCase();
odd+=el;
}
})
return [odd , even];
};
function getCount(str) {
var vowelsCount = 0;
let vowels = "aeiou"
str.split("").map(el => vowels.includes(el)? vowelsCount++:el )
return vowelsCount;
}
function findOdd(array) {
array.sort();
let num = [];
for(let i = 0; i < array.length ; i++){
if(array[i] == array[i+1] ){
i++
} else {
num = array[i]
}
}
return num;
}
function toFreud(string) {
if(string === "") return "";
return string.split(" ").map(el => "sex").join(" ");
}