fix: added 12 missing solutions to Basic Data Structure Challenges (#35744)
This commit is contained in:
committed by
The Coding Aviator
parent
75293e649d
commit
6a859ee7f9
@ -60,6 +60,12 @@ console.log(mixedNumbers(['IV', 5, 'six']));
|
|||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
```js
|
```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>
|
</section>
|
||||||
|
@ -61,6 +61,9 @@ console.log(htmlColorNames(['DarkGoldenRod', 'WhiteSmoke', 'LavenderBlush', 'Pal
|
|||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// solution required
|
function htmlColorNames(arr) {
|
||||||
|
arr.splice(0,2,'DarkSalmon', 'BlanchedAlmond');
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
@ -69,6 +69,16 @@ console.log(foods);
|
|||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
```js
|
```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>
|
</section>
|
||||||
|
@ -62,6 +62,10 @@ console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));
|
|||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// solution required
|
function quickCheck(arr, elem) {
|
||||||
|
// change code below this line
|
||||||
|
return arr.indexOf(elem) >= 0;
|
||||||
|
// change code above this line
|
||||||
|
}
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
@ -56,6 +56,8 @@ console.log(forecast(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms']
|
|||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// solution required
|
function forecast(arr) {
|
||||||
|
return arr.slice(2,4);
|
||||||
|
}
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
@ -68,6 +68,14 @@ let myNestedArray = [
|
|||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
```js
|
```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>
|
</section>
|
||||||
|
@ -65,6 +65,16 @@ console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
|
|||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
```js
|
```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>
|
</section>
|
||||||
|
@ -75,6 +75,29 @@ console.log(addFriend(user, 'Pete'));
|
|||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
```js
|
```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>
|
</section>
|
||||||
|
@ -66,6 +66,15 @@ console.log(userActivity);
|
|||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// solution required
|
let userActivity = {
|
||||||
|
id: 23894201352,
|
||||||
|
date: 'January 1, 2017',
|
||||||
|
data: {
|
||||||
|
totalUsers: 51,
|
||||||
|
online: 42
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
userActivity.data.online = 45;
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
@ -60,6 +60,10 @@ console.log(popShift(['challenge', 'is', 'not', 'complete']));
|
|||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// solution required
|
function popShift(arr) {
|
||||||
|
let popped = arr.pop(); // change this line
|
||||||
|
let shifted = arr.shift(); // change this line
|
||||||
|
return [shifted, popped];
|
||||||
|
}
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
@ -59,6 +59,9 @@ console.log(sumOfTen([2, 5, 1, 5, 2, 1]));
|
|||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// solution required
|
function sumOfTen(arr) {
|
||||||
|
arr.splice(2,2);
|
||||||
|
return arr.reduce((a, b) => a + b);
|
||||||
|
}
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
@ -57,6 +57,6 @@ let yourArray; // change this line
|
|||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// solution required
|
let yourArray = ['a string', 100, true, ['one', 2], 'another string'];
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
Reference in New Issue
Block a user