Created
February 6, 2019 13:33
-
-
Save VIRGO96/dba833b6a73918422a1bc423ba95b88b to your computer and use it in GitHub Desktop.
Test Answers for ITWal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Question 1 | |
indexOf returns the integer value | |
and when you attach ! with it it returns true | |
so instead of checking for true or false we can | |
check the integers | |
function myFunction() { | |
var str="Superman OS running"; | |
if (str.toLowerCase().indexOf('superman') == -1) { | |
console.log('String does not contain superman'); | |
} | |
} | |
Question 2 | |
functions Search(searchvalue) | |
{ | |
var arr=[1,2,3,4,5]; | |
for(var i=0;i<arr.length;i++) | |
{ | |
if(searchvalue==arr[i]) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} | |
Question 3 | |
const formatPhone = (str, delimiter = '-') => { | |
str = str.trim() | |
let phone = '' | |
for(let n of str){ | |
if(n === ' ' || isNaN(+n)){ | |
continue | |
} | |
phone += n | |
} | |
if(!phone || phone.length !== 10){ | |
throw Error(`Invalid phone number ${str}`) | |
} | |
return phone.substr(0, 3) | |
+ delimiter | |
+ phone.substr(3, 3) | |
+ delimiter | |
+ phone.substr(0, 4); | |
}; | |
Question 4 | |
it('should return valid for index 1') | |
it('should return valid for index 2') | |
it('should return valid for index 3') | |
it('should return valid for index 4') | |
it('should return valid for index 5') | |
it('should return valid for index 14') | |
it('should return valid for index 15') | |
it('should return valid count of symbols for 100') | |
Question 5 | |
function filterFiles(items, ignore) { | |
const lenItems = items.length; | |
const lenIgnore = ignore.length; | |
let c = 0; | |
let output = []; | |
for (let i = 0; i < lenItems; i++) { | |
let j = 0; | |
let k = 0; | |
while ( | |
ignore[j] !== items[i] && | |
items[i].indexOf(ignore[j]) !== 0 && | |
j < lenIgnore | |
) { | |
j++; | |
} | |
while (output[k] !== items[i] && k < c) { | |
k++; | |
} | |
if (j == lenIgnore && k == c) { | |
output[c++] = items[i]; | |
} | |
} | |
return output; | |
} | |
Question 6 | |
Couldnt understand the question | |
Question 7 | |
You clicked button #0 | |
You clicked button #3 | |
//Because the index is starting from 0 | |
Question 8 | |
const isIterable = (obj) => { | |
try { | |
return typeof obj[Symbol.iterator] === 'function' | |
}catch(e){ | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment