/javascript-codewars-archive

40-JavaScript exercises/tests - CodeWars - archive (TOTAL SOLUTIONS -- 87-Ruby, 40-JavaScript, 28-Python, 25-PHP) (RANK -- 90th percentile)

Primary LanguageJavaScript

JavaScript CodeWars Review

Archive of completed CodeWars exercises, languages - JavaScript

Short description and numbered in chronological order.

JAVASCRIPT

  • 1 Utilize Math.PI and conditional - alternate solutions, just fooling around

  • 2 Calculate the decibel of a sound wave, given its intensity as a parameter for the dBScale/db_scale function

  • 3 Given an object (array) of integers, return the binary equivalent of the sum of the elements

  • 4 Fix the below javascript code without removing any lines of code. The intended output is Hello World.

  • 5 Work with OOP, javascript - introduction to constructor concept, differs from ruby - experimenting

  • 6 Fix this helloWorld function

  • 7 Return string with no whitespace, form object (string)

  • 8 Write function avg which calculates average of numbers in given list.

  • 9 Write a method sum (sum_array in python) that takes an array of numbers and returns the sum of the numbers. These may be integers or decimals for Ruby and any instance of Num for Haskell. The numbers can also be negative. If the array does not contain any numbers then you should return 0.

  • 10 In javascript, Array is one of basic data types. Define an empty array can use var arr=new Array() or var arr=[]

    Array has an attribute: length, if there is an array named arr, using arr.length to know how many elements are
    contained in the array.

    Each element in the array has an index, use arr[index] to get the value of element.

    index always start from 0, so the first element of array is arr[0], the last element of array is arr[arr.length-1].

    If we want to add new elements to the array, you can use the array method: push(). It can add an element to the end of the array. Instead, if we want to remove the last element of the array, you can use the array method: pop(). for example:

  • 11 I've create three function, and defined some global variables, please select some variables that can make up the name of the function, and return them(Please note the uppercase and lowercase letters are different).

After mission 1 finished. you should click "Submit" to see my three questions, and write the answer in function answer1, answer2,answer3

  • 12 Find the last element of a list.

  • 13 As you probably know, Fibonacci sequence are the numbers in the following integer sequence: 1, 1, 2, 3, 5, 8, 13... Write a method that takes the index as an argument and returns last fibonacci number.

  • 14 (could not solve with JavaScript - this is someone elses solution)!!! --- Kept getting infinite, (index) to high

As you probably know, Fibonacci sequence are the numbers in the following integer sequence: 1, 1, 2, 3, 5, 8, 13... Write a method that takes the index as an argument and returns last digit of (index) fibonacci number.

  • 15 At the annual family gathering, the family likes to find the oldest living family member’s age and the youngest family member’s age and calculate the difference between them.

You will be given an array of all the family members' ages, in any order. The ages will be given in whole numbers,
so a baby of 5 months, will have an ascribed ‘age’ of 0. Return a new array with [youngest age, oldest age, difference between the youngest and oldest age].

  • 16 Concatenate strings.

  • 17 Create a function that takes an integer as an argument and returns "Even" for even numbers or "Odd" for odd numbers.

  • 18 Simple, remove the spaces from the string, then return the resultant string.

  • 19 Remove a exclamation mark from the end of string. For a beginner kata, you can assume that the input data is always a string, no need to verify it.

  • 20 You need to write a function that reverses the words in a given string. A word can also fit an empty string. If this is not clear enough, here are some examples:

  • 21 Write a function to split a string and convert it into an array of words.

  • 22 We need a function that can transform a number/boolean into a string. What ways of achieving this do you know?

  • 23 Your task is to make two functions, max and min (maximum and minimum in PHP) that take a(n) array/vector of integers list as input and outputs, respectively, the largest and lowest number in that array/vector.

  • 24 The function findDigit takes two numbers as input, num and nth. It outputs the nth digit of num (counting from right to left).

    Note

    If num is negative, ignore its sign and treat it as a positive value. If nth is not positive, return -1. Keep in mind that 42 = 00042. This means that findDigit(42, 5) would return 0.

  • 25 We need a function that can transform a string into a number. What ways of achieving this do you know?

  • 26 A function is a block of code that takes an input and produces an output. In this example, boolean_to_string is a function whose input is either true or false, and whose output is the string representation of the input, either "true" or "false".

  • 27 Complete the bool_to_word (Javascript: boolToWord ) method. Given: a boolean value Return: a 'Yes' string for true and a 'No' string for false

  • 28 It's the academic year's end, fateful moment of your school report. The averages must be calculated. All the students come to you and entreat you to calculate their average for them. Easy ! You just need to write a script. Return the average of the given array rounded down to its nearest integer. The array will never be empty.

  • 29 Make a function that counts how many more (or less) pieces of toast you need in the toasters, you want 6 pieces. Even though you may need more or less, the number will still be positive, not negative.

  • 30 Debug this function to make the tests pass, operations ( +, * ) on arrays, and the reverse of a string in an interesting way.

  • 31 I created this function to add five to any number that was passed in to it and return the new value. It doesn't throw any errors but it returns the wrong number.

  • 32 Timmy & Sarah think they are in love, but around where they live, they will only know once they pick a flower each. If one of the flowers has an even number of petals and the other has an odd number of petals it means they are in love.

Write a function that will take the number of petals of each flower and return true if they are in love and false if they aren't.

  • 33 Positive integers that are divisible exactly by the sum of their digits are called Harshad numbers, see Wikipedia for further details. Write a function numberJoy() which tests if a positive integer n is Harshad and returns True if the product of its digit sum, and its digit sum reversed, equals n. Otherwise return False.

  • 34 Invert a given list of integer values.

  • 35 "Plural" - We need a simple function that determines if a plural is needed or not. It should take a number, and return true if a plural should be used with that number or false if not. This would be useful when printing out a string such as 5 minutes, 14 apples, or 1 sun.

  • 36 "Get length of the list recursively" - Write function lenR which returns the length of a given list. Try no to cheat and provide recursive solution.

  • 37 "Circle area inside square" - Turn an area of a square in to an area of a circle that fits perfectly inside the square.

  • 38 (LVL 8) "Sort and Star" - You will be given an vector of string(s). You must sort it alphabetically (case-sensitive!!) and then return the first value. The returned value must be a string, and have ' * * * ' between each of its letters.

  • 39 (LVL 7) "Square(n) Sum" - Complete the squareSum method so that it squares each number passed into it and then sums the results together.

  • 40 (LVL 8) "Counting Sheep" - Consider an array of sheep where some sheep may be missing from their place. We need a function that counts the number of sheep present in the array (true means present). NOTE: Array of true/false booleans, to be clear.

  • 41 (LVL 8) "simple calculator" - You are required to create a simple calculator that returns the result of addition ,subtraction , multiplication and division of two numbers . example

calculator(1,2,"+"); //=> result will be 3 if the variables are not numbers or the sign does not belong to the list above a message "unknown value" must be returned.