Skip to content

Commit

Permalink
Import third party lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakai-san committed Dec 4, 2017
1 parent 5db0b67 commit e285fb5
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 10 deletions.
74 changes: 64 additions & 10 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,74 @@
const pythagoras = ( vector ) => {
const underscore = require('../node_modules/underscore');


/**
* vector norm
*
* @desc compute the norm of vector with n components
* @param {Array<Number>} vector - components of a vector
* @returns {Number}
*/

const vectorNorm = ( vector ) => {
const squareSum = vector
.map( (component) => component*component)
.reduce( (memo, square) => memo+square );
return Math.sqrt(squareSum);
}

const triplets = [
[3, 4],
[3, 4],
[3, 4, 5],
[5, 12, 13],
[8, 15, 17],
[7, 24, 25],
[20, 21, 29],
[12, 35, 37],
[9, 40, 41],
[28, 45, 53],
[11, 60, 61],
[16, 63, 65],
[33, 56, 65],
[48, 55, 73],
[13, 84, 85],
[36, 77, 85],
[39, 80, 89],
[65, 72, 97],
];


/*
(3, 4, 5) (5, 12, 13) (8, 15, 17) (7, 24, 25)
(20, 21, 29) (12, 35, 37) (9, 40, 41) (28, 45, 53)
(11, 60, 61) (16, 63, 65) (33, 56, 65) (48, 55, 73)
(13, 84, 85) (36, 77, 85) (39, 80, 89) (65, 72, 97)
*/
console.log( pythagoras(triplets) );
const Candidate = function(name, birthDate) {
this.name = name,
this.birthDate = birthDate,
this.getAge = () => {
const dateDiff = new Date( Date.now() - new Date(this.birthDate) );
return Math.abs(dateDiff.getUTCFullYear() - 1970);
}
};


const Job = function(startDate, endDate, jobDescription, company) {
this.startDate = startDate,
this.birthDate = endDate,
this.getDuration = () => {
const dateDiff = new Date( Date.now() - new Date(this.birthDate) );
return Math.abs(dateDiff.getUTCFullYear() - 1970);
}
};


// test pythagoras
triplets.forEach ( (triplet) => {
console.log("solution : " +triplet[2]);
console.log( vectorNorm(triplet.slice(2) ));
console.log("_______________________");
});

// test candidate
const candidate1 = new Candidate( "sebastian", "1980-10-12" );

console.log( candidate1.getAge() );


const Experiences = ( (jobs) => {
return jobs;
});
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"underscore": "*"
}
}
34 changes: 34 additions & 0 deletions yarn-error.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Arguments:
/home/toma/.nvm/versions/node/v8.8.0/bin/node /home/toma/.yarn/bin/yarn.js install

PATH:
/home/toma/.yarn/bin:/home/toma/.yarn/bin:/home/toma/.nvm/versions/node/v8.8.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Yarn version:
1.3.2

Node version:
8.8.0

Platform:
linux x64

npm manifest:
"dependencies": {
"underscore": "*"
}

yarn manifest:
No manifest

Lockfile:
No lockfile

Trace:
SyntaxError: /opt/lampp/htdocs/filtering/package.json: Unexpected token : in JSON at position 14
at JSON.parse (<anonymous>)
at /home/toma/.yarn/lib/cli.js:770:59
at Generator.next (<anonymous>)
at step (/home/toma/.yarn/lib/cli.js:92:30)
at /home/toma/.yarn/lib/cli.js:103:13
at <anonymous>
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


underscore@*:
version "1.8.3"
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.8.3.tgz#4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022"

0 comments on commit e285fb5

Please sign in to comment.