Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ArithmeticServer.js → ArithmeticServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ http.createServer(function (request, response) {
ans = 'num must be used with fibonacci pathname!';
}
else {
n = parseInt(queryData.num);
let n:number = parseInt(queryData.num);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract parseInt to a function to better encapsulate how to parse ints.

if (n < 0) {
ans = 'no fibonacci response for negative values, num =' + num;
ans = 'no fibonacci response for negative values, num =' + queryData.num;
}
else {
ans = fibonaci(n);
Expand Down Expand Up @@ -67,11 +67,11 @@ http.createServer(function (request, response) {
console.log('running - listening on port ', port);


function fibonaci(n) {
function fibonaci(n:number) {
if ((1 == n) || (0 == n) ) {
return 1;
}
else {
return (fibonaci(n-1) + fibonaci(n-2));
}
}
}
2 changes: 1 addition & 1 deletion Fibo1.js → Fibo1.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Created by User on 3/17/14.
*/
function fibonaci(n) {
function fibonaci(n:number) {
if ((1 == n) || (0 == n) ) {
return 1;
}
Expand Down
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "lesson02",
"version": "1.0.0",
"description": "lesson02 ========",
"main": "ArithmeticServer.js",
"dependencies": {
Linkgoron marked this conversation as resolved.
Show resolved Hide resolved
"typescript": "^3.5.3"
},
"devDependencies": {
"@types/node": "^12.7.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Ilantc",
"license": "ISC"
}
2 changes: 1 addition & 1 deletion polyn.js → polyn.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Created by User on 3/17/14.
*/
function isPolyndrom(a) {
function isPolyndrom(a:string) {
for(var i = 0, j =a.length-1 ; i < j ; i++,j--){
if (a.charAt(i) != a.charAt(j)) {
return false;
Expand Down