Last active
November 21, 2019 07:23
-
-
Save chuck0523/b168a62d230dd1c0936f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var log = function(x) { | |
console.log(x); | |
}; | |
var void_text = ''; | |
// 口調 | |
function getWords(type) { | |
switch(type) { | |
case 'normal': | |
return ['僕の', 'は', 'です。']; | |
case 'wild': | |
return ['俺の', 'は', 'だぜぇ。']; | |
case 'english': | |
return ['My ', ' is ', '.']; | |
default : | |
return ['私の', 'は', 'です。']; | |
}; | |
} | |
// 個人情報 | |
var | |
my_data = [ | |
['名前', 'chuck'], | |
['年齢', '24歳'], | |
['身長', '183cm'], | |
['血液型', 'B型'] | |
], | |
someone_data = [ | |
['名前', 'bob'], | |
['年齢', '50歳'], | |
['身長', '198cm'], | |
['血液型', 'AB型'] | |
]; | |
// 自己紹介に特化された高階関数 | |
// 人、口調に関していっさい規定しない | |
function aboutMe(speak) { | |
return function(data) { | |
data.forEach(function(e) { | |
log(speak[0] + e[0] + speak[1] + e[1] + speak[2]); | |
}); | |
}; | |
} | |
// 関数のセット | |
var aboutChuck = aboutMe(getWords('normal')); | |
// 関数の実行 | |
aboutChuck(my_data); | |
log(void_text); | |
var aboutChuckWild = aboutMe(getWords('wild')); | |
aboutChuckWild(my_data); | |
log(void_text); | |
var aboutChuckEnglish = aboutMe(getWords('english')); | |
aboutChuckEnglish(my_data); | |
log(void_text); | |
var aboutSomeone = aboutMe(getWords('normal')); | |
aboutSomeone(someone_data); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment