Skip to content

Commit de1a2d7

Browse files
committed
js arrays
1 parent 5c6ac7d commit de1a2d7

3 files changed

Lines changed: 66 additions & 0 deletions

File tree

js-arrays/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Manipulating JavaScript Arrays
2+
3+
> [https://youtu.be/KhQkErkEips](https://youtu.be/KhQkErkEips)
4+
5+
Install [io.js](https://iojs.org/en/index.html).
6+
7+
Within this folder run the terminal command `npm install` to install the
8+
`devDependencies`.
9+
10+
Then run `npm start` to start up a development server on `http://localhost:9966`

js-arrays/index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// var list = [1, 'string', { type: true }, [1,2,3]];
2+
//
3+
// list.push('at the end');
4+
// list.unshift('at the beginning');
5+
//
6+
// // list.forEach(function (item) {
7+
// // console.log(item);
8+
// // });
9+
//
10+
// var firstitem = list.shift();
11+
// console.log(firstitem);
12+
13+
var bears = ['grizzly', 'polar', 'brown'];
14+
15+
bears.splice(bears.indexOf('polar'), 1);
16+
17+
console.log(bears);
18+
19+
// var last2 = bears.slice(-2);
20+
// console.log(last2);
21+
22+
// var longestbear = bears.reduce(function (prev, next) {
23+
// if (next.length > prev.length) return next;
24+
// return prev;
25+
// });
26+
//
27+
// console.log(longestbear);
28+
29+
// bears = bears.filter(function (bear) {
30+
// return bear !== 'polar';
31+
// }).map(function (bear) {
32+
// var li = document.createElement('li');
33+
// li.textContent = bear;
34+
// return li;
35+
// });
36+
//
37+
// var ul = document.createElement('ul');
38+
// bears.forEach(function (element) {
39+
// ul.appendChild(element);
40+
// });
41+
// document.body.appendChild(ul);

js-arrays/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "js-arrays",
3+
"version": "0.1.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "budo index.js --live",
8+
"test": "node test.js"
9+
},
10+
"author": "Kyle Robinson Young <kyle@dontkry.com> (http://dontkry.com)",
11+
"license": "MIT",
12+
"devDependencies": {
13+
"budo": "^4.1.0"
14+
}
15+
}

0 commit comments

Comments
 (0)