JSFiddle

  • Falsy Bouncer

    Remove all falsy values from an array. Falsy values in JavaScript are false, null, 0, "", undefined, and NaN.

    function bouncer(arr) {
      // Don't show a false ID to this bouncer.
    
      return arr.filter(Boolean);
    }
    
    bouncer([7, "ate", "", false ...
  • Mutations

    Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.

    function mutation(arr) {
      var arr1 = arr[1].toLowerCase();
      var arr2 = arr[0].toLowerCase();
    
      for (var i = 0; i < arr1.length ...
  • Slasher Flick

    Return the remaining elements of an array after chopping off n elements from the head. The head means the beginning of the array, or the zeroth index.

    function slasher(arr, howMany) {
      // it doesn't always pay to be first
    
    
      arr.splice(0, howMany);
      return arr;
    }
    
    slasher(["burgers ...
  • Chunky Monkey

    Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array.

    function chunkArrayInGroups(arr, size) {
      var newArray = [];
      var oldArray = arr.length / size;
      for (var i = 0; i < oldArray; i++) {
        var array ...
  • Repeat a string repeat a string

    Repeat a given string (first argument) num times (second argument). Return an empty string if num is not a positive number.

    function repeat(str, num) {
      // repeat after me
      var newString = "";
      while (num > 0) {
        newString += str;
        num--;
      }
      return newString;
    }
    
    repeat("abc", 3);
    
  • Confirm the Ending

    Check if a string (first argument, str) ends with the given target string (second argument, target). This challenge can be solved with the .endsWith() method, which was introduced in ES2015. But for the purpose of this challenge, we would like you to use one of the JavaScript substring methods instead.

    function end(str, target) {
      // "Never give up and good luck will find you."
      // -- Falcor
    
    
      var length = target.length;
      var isEqual ...
  • Return Largest Numbers in Arrays

    Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.

    function largestOfFour(arr) {
      // You can do this!
    
      var results = [];
    
      for (var i = 0; i < arr.length; i++) {
        var largeNum = 0;
    
        for (var n = 0; n < arr[i].length; n++) {
          if (arr[i][n] > largeNum) {
            largeNum = arr[i][n];
          }
        }
        results ...
  • Title Case a Sentence

    Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case. For the purpose of this exercise, you should also capitalize connecting words like "the" and "of".

    function titleCase(str) {
      var arrayList = str.split(' ');
    
      for (var i = 0; i < arrayList.length; i++) {
        var eaElement = arrayList[i];
        var ...
  • Find the Longest Word in a String

    Return the length of the longest word in the provided sentence. Your response should be a number.

    function findLongestWord(str) {
      var words = str.split(' ');
    
      var longest = 0;
    
      for (var i = 0; i < words.length; i++) {
        if (words[i].length > longest) {
          longest = words[i].length ...
  • Check for Palindromes

    Return true if the given string is a palindrome. Otherwise, return false.

    function palindrome(str) {
      str = str.toLowerCase().replace(/[\W_]/g, '');
      for (var i = 0, len = str.length - 1; i < len / 2 ...