fix: added 12 missing solutions to Basic Data Structure Challenges (#35744)

This commit is contained in:
Randell Dawson
2019-04-10 08:33:15 -07:00
committed by The Coding Aviator
parent 75293e649d
commit 6a859ee7f9
12 changed files with 94 additions and 12 deletions

View File

@ -60,6 +60,12 @@ console.log(mixedNumbers(['IV', 5, 'six']));
<section id='solution'>
```js
// solution required
function mixedNumbers(arr) {
// change code below this line
arr.push(7,'VIII',9);
arr.unshift('I',2,'three');
// change code above this line
return arr;
}
```
</section>

View File

@ -61,6 +61,9 @@ console.log(htmlColorNames(['DarkGoldenRod', 'WhiteSmoke', 'LavenderBlush', 'Pal
<section id='solution'>
```js
// solution required
function htmlColorNames(arr) {
arr.splice(0,2,'DarkSalmon', 'BlanchedAlmond');
return arr;
}
```
</section>

View File

@ -69,6 +69,16 @@ console.log(foods);
<section id='solution'>
```js
// solution required
let foods = {
apples: 25,
oranges: 32,
plums: 28
};
// change code below this line
foods['bananas'] = 13;
foods['grapes'] = 35;
foods['strawberries'] = 27;
// change code above this line
```
</section>

View File

@ -62,6 +62,10 @@ console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));
<section id='solution'>
```js
// solution required
function quickCheck(arr, elem) {
// change code below this line
return arr.indexOf(elem) >= 0;
// change code above this line
}
```
</section>

View File

@ -56,6 +56,8 @@ console.log(forecast(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms']
<section id='solution'>
```js
// solution required
function forecast(arr) {
return arr.slice(2,4);
}
```
</section>

View File

@ -68,6 +68,14 @@ let myNestedArray = [
<section id='solution'>
```js
// solution required
let myNestedArray = [
// change code below this line
['unshift', ['deep', ['deeper', ['deepest']]],false, 1, 2, 3, 'complex', 'nested'],
['loop', 'shift', 6, 7, 1000, 'method'],
['concat', false, true, 'spread', 'array'],
['mutate', 1327.98, 'splice', 'slice', 'push'],
['iterate', 1.3849, 7, '8.4876', 'arbitrary', 'depth']
// change code above this line
];
```
</section>

View File

@ -65,6 +65,16 @@ console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
<section id='solution'>
```js
// solution required
function filteredArray(arr, elem) {
let newArr = [];
// change code below this line
for (let i = 0; i<arr.length; i++) {
if (arr[i].indexOf(elem) < 0) {
newArr.push(arr[i]);
}
}
// change code above this line
return newArr;
}
```
</section>

View File

@ -75,6 +75,29 @@ console.log(addFriend(user, 'Pete'));
<section id='solution'>
```js
// solution required
let user = {
name: 'Kenneth',
age: 28,
data: {
username: 'kennethCodesAllDay',
joinDate: 'March 26, 2016',
organization: 'freeCodeCamp',
friends: [
'Sam',
'Kira',
'Tomo'
],
location: {
city: 'San Francisco',
state: 'CA',
country: 'USA'
}
}
};
function addFriend(userObj, friend) {
userObj.data.friends.push(friend);
return userObj.data.friends;
}
```
</section>

View File

@ -66,6 +66,15 @@ console.log(userActivity);
<section id='solution'>
```js
// solution required
let userActivity = {
id: 23894201352,
date: 'January 1, 2017',
data: {
totalUsers: 51,
online: 42
}
};
userActivity.data.online = 45;
```
</section>

View File

@ -60,6 +60,10 @@ console.log(popShift(['challenge', 'is', 'not', 'complete']));
<section id='solution'>
```js
// solution required
function popShift(arr) {
let popped = arr.pop(); // change this line
let shifted = arr.shift(); // change this line
return [shifted, popped];
}
```
</section>

View File

@ -59,6 +59,9 @@ console.log(sumOfTen([2, 5, 1, 5, 2, 1]));
<section id='solution'>
```js
// solution required
function sumOfTen(arr) {
arr.splice(2,2);
return arr.reduce((a, b) => a + b);
}
```
</section>

View File

@ -57,6 +57,6 @@ let yourArray; // change this line
<section id='solution'>
```js
// solution required
let yourArray = ['a string', 100, true, ['one', 2], 'another string'];
```
</section>