Test case details

Preparation Code

Test cases

Test #1

responseStatusCodes = { no_response: 0, info: 1, success: 2, redirect: 3, clientError: 4, serverError: 5 } function getKeyByValue(object, value) { return Object.keys(object).find(key => object[key] === value); } const firstIntegerUsingString = function(integer) { var digit = parseInt(integer.toString()[0]); console.log(getKeyByValue(responseStatusCodes, digit)); return digit; } for(let x = 0; x<600; x+=100) { console.log(firstIntegerUsingString(x)); }

Test #2

responseStatusCodes = { no_response: 0, info: 1, success: 2, redirect: 3, clientError: 4, serverError: 5 } function getKeyByValue(object, value) { return Object.keys(object).find(key => object[key] === value); } const firstIntegerUsingMath = function(integer) { const len = String(Math.abs(integer)).length; const divisor = 10 ** (len - 1); // 2: get integer part from result of division const digit = Math.trunc(integer/divisor); console.log(getKeyByValue(responseStatusCodes, digit)); return digit; } for(let x = 0; x<600; x+=100) { console.log(firstIntegerUsingMath(x)); }