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

TP1 #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

TP1 #20

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
14 changes: 14 additions & 0 deletions browser/lessons/lesson_01-base/lexical-analyzer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** A simple lexical analyzer
*/


/** tokenize a string = split it into words
*
* Note : space separated only for now
Expand All @@ -10,6 +11,8 @@
*/
export function tokenize(str) {
// Write code here so that it passes the tests
var allTokens = str.split(" ");
return allTokens.filter(item => item.length != 0);
}

/** stem a string = turn several variants into the same
Expand All @@ -20,6 +23,7 @@ export function tokenize(str) {
*/
export function stem(str) {
// Write code here so that it passes the tests
return str.toLowerCase(str);
}

/** parse a string into a list of stemmed token
Expand All @@ -30,6 +34,7 @@ export function stem(str) {
*/
export function parse(str) {
// Write code here so that it passes the tests
return tokenize(stem(str));
}

/** index a string into a hash {'token' : <frequency of appearance>}
Expand All @@ -39,6 +44,15 @@ export function parse(str) {
*/
export function index(str) {
// Write code here so that it passes the tests
let rawList = parse(str);
let result = {};
rawList.forEach(function (item) {
if (result[item] == undefined)
result[item] = 1;
else
result[item] += 1;
});
return result;
}


Expand Down
9 changes: 9 additions & 0 deletions browser/lessons/lesson_03-type_detection/boolean-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
*/
export default function convertToBoolean(value) {
// TODO write the function so it passes the tests below !
if (typeof value == 'boolean')
return value;
if (value == 'true')
return true;
if (value == 'false')
return false;
if (typeof value == 'string' && value.length > 0)
return false;
return new Boolean(value).valueOf();
}


Expand Down
24 changes: 18 additions & 6 deletions browser/lessons/lesson_04-logger/logger.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
import _ from 'lodash';

function createFancyLogger(id) {
id = (id || 'default').toUpperCase();
id = (id || 'default');

function logBetter(level) {
const originalArgs = Array.from(arguments);

// TODO implement !
let newArgs = originalArgs;
let newArgs = originalArgs.slice(1);
// TODO....
let callerParams = newArgs.slice(0);

let prefix = getTimestamp(new Date(0)) + " - " + id + " - ";
newArgs.unshift(prefix);

let output = prefix;
//if (! (callerParams[0].includes("%s") || callerParams[0].includes("%d")))
output = prefix + callerParams[callerParams.length - 1];
//else
//output = prefix +

console[originalArgs[0]](output);
}

/* eslint-disable no-undefined */
return {
log: undefined,
info: undefined,
warn: undefined,
error: undefined,
log: logBetter.bind(undefined, 'log'),
info: logBetter.bind(undefined, 'info'),
warn: logBetter.bind(undefined, 'warn'),
error: logBetter.bind(undefined, 'error'),
};
}

Expand Down