Skip to content

Instantly share code, notes, and snippets.

let result = 0;
[1,2,3,4,5,6].forEach((n) => {
if (n % 2 === 0) {
result += n * n;
}
});
console.log(result);
const result = [1,2,3,4,5,6]
.filter(n => n % 2 === 0)
.map(n => n * n)
.reduce((a, b) => a + b, 0);
console.log(result); // (2*2) + (4*4) + (6*6)
// https://github.com/j5ik2o/ticket-price-modeling
// 解き方方針: 型で問題を解くよりも、料金表のように日本人の非エンジニアの人も読めて突っ込めるコード記述を目指す.
// 解き方方針: 配列でmap&sortの世界に引き込んで安い料金を選ぶようにする.
// 解いたのは "シネマシティズン" の場合だけ。
// TODO 引数を型にして呼び出しに制約を設けるかはあとで考える。
const movePayment = (ticketType, timeTypes) => {
var payments =
{"シネマシティズン":
{"平日〜20:00": 1000,
interface Expression {
times(muptiplier: number): Expression;
plus(addend: Expression): Expression;
reduce(bank: Bank, to: string): Money
}
class Money implements Expression {
private _amount: number
private _currency: string
function createReportData(readList, recommendList) {
const reportData = {};
reportData.userName = readList.name;
reportData.readBooks = readList.books
.map(book => {
return {...book, point: point(book)};
});
reportData.total = total(reportData);
return reportData;
const createReportData = require('./createReportData');
function generateReadReport(readList, recommendList) {
const reportData = createReportData(readList, recommendList);
return renderPlainText(reportData);
}
function renderPlainText(reportData) {
let report = `name: ${reportData.userName}\n`;
report += '-----\n';
@haru01
haru01 / 18.js
Last active April 4, 2019 01:54
function generateReadReport(readList, recommendList) {
const reportData = createReportData(readList, recommendList);
return renderPlainText(reportData);
}
function createReportData(readList, recommendList) {
const reportData = {};
reportData.userName = readList.name;
reportData.readBooks = readList.books
.map(book => {
@@ -1,6 +1,6 @@
function generateReadReport(readList, recommendList) {
const reportData = createReportData(readList, recommendList);
- return renderPlainText(reportData, recommendList);
+ return renderPlainText(reportData);
}
function createReportData(readList, recommendList) {
@@ -42,7 +42,7 @@ function createReportData(readList, recommendList) {
}
@@ -10,8 +10,14 @@ function createReportData(readList, recommendList) {
.map(book => {
return {...book, point: point(book)};
});
+ reportData.total = total(reportData);
return reportData;
+ function total(reportData) {
+ return reportData.readBooks
+ .reduce((total, book) => total + book.point, 0);
@haru01
haru01 / 15.js
Last active April 4, 2019 01:41
function renderPlainText(reportData, recommendList) {
let report = `name: ${reportData.userName}\n`;
report += '-----\n';
for (let book of reportData.readBooks) {
if (book.times >= 1) {
report += ` - ${book.name}: ${book.point} point\n`;
}
}
report += '-----\n';
report += `total: ${total()} point`;