Skip to content

Commit b2fa53c

Browse files
committed
Basic data structure
1 parent 227ab10 commit b2fa53c

20 files changed

+212
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let yourArray = ['one', 2, 'three', true, false, undefined, null]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let myArray = ["a", "b", "c", "d"];
2+
myArray[1] = "g"
3+
console.log(myArray);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function mixedNumbers(arr) {
2+
arr.unshift("I", 2, "three");
3+
arr.push(7, "VIII", 9);
4+
return arr;
5+
}
6+
7+
console.log(mixedNumbers(['IV', 5, 'six']));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function popShift(arr) {
2+
let popped = arr.pop();
3+
let shifted = arr.shift();
4+
return [shifted, popped];
5+
}
6+
7+
console.log(popShift(['challenge', 'is', 'not', 'complete']));
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const arr = [2, 4, 5, 1, 7, 5, 2, 1];
2+
arr.splice(2, 1);
3+
arr.splice(3, 2);
4+
console.log(arr);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function htmlColorNames(arr) {
2+
arr.splice(0, 2, 'DarkSalmon', 'BlanchedAlmond');
3+
return arr;
4+
}
5+
6+
console.log(htmlColorNames(['DarkGoldenRod', 'WhiteSmoke', 'LavenderBlush', 'PaleTurquoise', 'FireBrick']));
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function forecast(arr) {
2+
arr = arr.slice(2, 4);
3+
return arr;
4+
}
5+
6+
console.log(forecast(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms']));
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function copyMachine(arr, num) {
2+
let newArr = [];
3+
while (num >= 1) {
4+
newArr.push([...arr]);
5+
num--;
6+
}
7+
return newArr;
8+
}
9+
10+
console.log(copyMachine([true, false, true], 2));
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function spreadOut() {
2+
let fragment = ['to', 'code'];
3+
let sentence = ['learning', ...fragment, 'is', 'fun'];
4+
5+
return sentence;
6+
}
7+
8+
console.log(spreadOut());
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function quickCheck(arr, elem) {
2+
return arr.indexOf(elem) < 0 ? false : true;
3+
}
4+
5+
console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));

0 commit comments

Comments
 (0)