-
Notifications
You must be signed in to change notification settings - Fork 287
JavaScript Test 6
-
Explain the following questions in your own words
- What is the difference between forEach, map, filter and reduce ? Explain these using your own words
- Explain the difference between function declaration and arrow function ?
- Explain the difference between find and findIndex ?
- If you like to filter out one object element in an array which method do you like to use: filter or find ? Explain
- Explain the difference of var, let and const when we declare a variable ?
-
In English language some words come more often than others to a sentence. Write a function called mostFrequentWords it takes a sentence or a paragraph as a parameter and return an array of objects. The object is the word and its number of occurrence in the paragraph or in the sentence.
console.log(mostFrequentWords(paragraph))
-
Write a function called sumOfNumbers. It takes unlimited number of integers as parameters and it returns the sum.
- Implement this function using function declaration
- Implement this function using arrow function
-
Write a function which calculate mean, median and range of an array.
-
A junior developer structure student name, skills and score in array of arrays which may not easy to read. Destruction the following array name to name, skills array to skills, scores array to scores, JavaScript score to jsScore and React score to reactScore variable.
const student = ['David', ['HTM', 'CSS', 'JS', 'React'], [98, 85, 90, 95]] console.log(name, skills, scores, jsScore, reactScore)
-
Write a function called convertArrayToObject which can convert the array to a structure object.
const students = [
['David', ['HTM', 'CSS', 'JS', 'React'], [98, 85, 90, 95]],
['John', ['HTM', 'CSS', 'JS', 'React'], [85, 80, 85, 80]]
]
console.log(convertArrayToObject(students))
[
{
name: 'David',
skills: ['HTM','CSS','JS','React'],
scores: [98,85,90,95]
},
{
name: 'John',
skills: ['HTM','CSS','JS','React'],
scores: [85, 80,85,80]
}
]
-
Copy the student object to newStudent without mutating the original object. In the new object add the following ?
- Add Bootstrap with level 8 to the front end skill sets
- Add Express with level 9 to the back end skill sets
- Add SQL with level 8 to the data base skill sets
- Add SQL without level to the data science skill sets
const student = {
name: 'David',
age: 25,
skills: {
frontEnd: [
{ skill: 'HTML', level: 10 },
{ skill: 'CSS', level: 8 },
{ skill: 'JS', level: 8 },
{ skill: 'React', level: 9 }
],
backEnd: [
{ skill: 'Node',level: 7 },
{ skill: 'GraphQL', level: 8 },
],
dataBase:[
{ skill: 'MongoDB', level: 7.5 },
],
dataScience:['Python', 'R', 'D3.js']
}
}
```
The copied object output should look like this:
```js
{
name: 'David',
age: 25,
skills: {
frontEnd: [
{skill: 'HTML',level: 10},
{skill: 'CSS',level: 8},
{skill: 'JS',level: 8},
{skill: 'React',level: 9},
{skill: 'BootStrap',level: 8}
],
backEnd: [
{skill: 'Node',level: 7},
{skill: 'GraphQL',level: 8},
{skill: 'Express',level: 9}
],
dataBase: [
{ skill: 'MongoDB',level: 7.5},
{ skill: 'SQL',level: 8}
],
dataScience: ['Python','R','D3.js','SQL']
}
}
-
Use the student object to solve the following questions:
- Find the length of student object keys
- Find the length of the student object values
- Find the length of skills object keys
- check if the student object has graphicDesign property
- Iterate the keys of the student object
-
Make a function called add which give truthy value when add(a, b) === add(a)(b)
console.log(add(2,3)) //5 console.log(add(2)(3)) //5 console.log(add(2,3) === add(2)(3)) // true
-
Write a function called checkDataTypes it takes an array and a data type. It returns true if the array has the same data types.
const numbers = [1,3,4]
const names = ['Asab', 'Masood'];
const bools = [true, false, true, true, false]
const mixedData = ['Asab', 'JS', true, 2019, {name:'Asab', lang:'JS'}]
const object = [{name:'Asab', lang:'JS'}]
console.log(checkDataTypes(numbers, 'number')) // true
console.log(checkDataTypes(numbers, 'string')) // false
console.log(checkDataTypes(names, 'string')) // true
console.log(checkDataTypes(bool, 'boolean')) // true
console.log(checkDataTypes(mixedData, 'boolean')) // false
console.log(checkDataTypes(obj, 'object')) // true