article

you can't code javascript under pressure

[WHAT]

  1. [] this short timed quiz was popular for a while in 2013 ish, coding questions got progressively harder as you worked through the questions

[WHY]

  1. [] test your javascript coding skills in a time based scenario

[WHERE]

  1. [] TRY OUT THIS LEARNING TOOL
    1. [] http://games.usvsth3m.com/javascript-under-pressure/ 
    2. [x] UPDATED][2019-11-24] looks like the quiz is no longer online at the original host, 

[WHEN]

  1. [] 2013-10-dd
    1. [x] i completed 3/5 questions, was working the 4th, but not all tests were passing with my solution (edge cases), never attempted the fifth

[EXAMPLE]

  1. [] double the result
  2. [] determine if (odd?even) 
  3. [] extract the filename extension
  4. [] find the Longest String - 
  5. [] Sum all integers - The description of the problem asks us to “sum all integers you find, anywhere”. Well, this nested array has integers in it, doesn’t it? How do we add these to the count without borking up our iteration over each array index?

[HOW-TO]

  1. ] see below for my solutions/notes/comments, also REF 002 

[REFERENCE]

  1. [] leah verou posted her answers code to these tests on her blog
  2. [] http://zpalexander.com/you-cant-javascript-under-pressure/

 


 

1] function double the result

double the argument and return the results

function double(){

  return i*2; 

}

2] function determine (odd?even) 

Return true or false depending on whether the number is even.
You can use console.log() and alert(); the results will show up here

TIMER - 09:01 

3] extract filename extension

 
function getFileExtension(i) {
   
   
// i will be a string, but it may not have a file extension.
   
// return the file extension (with no period) if it has one, otherwise false
   
   
var len = i.length;
   
var result = true;
   
var arr = [];
   

/*
   
if ( i.indexOf('.') === undefined ){
        return false;
    }
   
*/
   
// grrrrrrrrrrrrrrrrr
    
// PRB WAS s first i.indexOf('.')
// if ( i.indexOf('.') && i.indexOf('.') >= 0 ){

if ( i.indexOf('.') >= 0 ){
        var x =  i.indexOf(".");
       
        if ( i.indexOf('.') >= 1){
            arr = i.split('.');
            return arr[1];
        }
       
        if (x === 0) {
            return i.slice(1);
        }
    }
    /*
    if ( i.indexOf('.')){
        arr = i.split('.');
        return arr[1];
    }
    if ( i.indexOf('.') === -1 ){
        result = false;
        return result;
    }
    */
   
    else{
         result = false;
         return result;
        //console.log("false");
    }

}

TIMER = 87.20 - ouch, ouch, ouch
SUCCESS! All tests passed. You've used 87:20 so far. Well done! Top work, that was tricky. Two challenges left! Ready to start the clock again?

4] find the longest string


function getUTF8ByteLength(s) {
    return unescape(encodeURIComponent(s)).length;
}

function longestString(i) {
    // i will be an array.
    // return the longest string in the array
    var myArray = i;
    for (x=0; x < myArray.length; x++){
        myArray[x].len = myArray[x].length;
    }
   
    myArray.sort(function(a, b) {
    return a.len - b.len;
    });
   
    return myArray[myArray.length-1];
}


function longestString(i) {
    // i will be an array.
    // return the longest string in the array
    var myArray = i;
   
    function getUTF8ByteLength(s) {
        return unescape(encodeURIComponent(s)).length;
    }
   
   
    for (x=0; x < myArray.length; x++){
        // myArray[x].len = myArray[x].length;
        myArray[x].len = getUTF8ByteLength(myArray[x]);
    }
   
    myArray.sort(function(a, b) {
    return a.len - b.len;
    });
   
    return myArray[myArray.length-1];
}

TIMER = 119.00 -abondoned

- this did not pass all tests, one test where string contains chinese characters indicates that the string with chinese characters (3) is longer then another string 'world' with 5 characters, likely some utf-8 encoding

5] sum all integers

 

Details Photos Edit more

Details

ID: 2585

NAME: code-quiz-you-cant-code-javascript-under-pressure

DESCRIPTION: code-quiz-you-cant-code-javascript-under-pressure - time based javascript code tests

AUTHOR: article.author/s

EDITOR: article.editor/s

PUBLISHER: article.publisher/s

STATUS: Write

PRIORITY: -5

OWNER ID: 75

Content Photos Edit more

photos

page_photo

actions

Email Email-Owner SMS and