浏览代码

Update README.md

Show how to call multi-arg method for arrays (calling multi-arg mehtod for
Kamil Kiełczewski 4 年之前
父节点
当前提交
02ba75676e
共有 1 个文件被更改,包括 20 次插入3 次删除
  1. 20 3
      README.md

+ 20 - 3
README.md

@@ -366,15 +366,32 @@ New characters:
 
 ### Calling method with more than one argument
 
-Calling a method with more than one argument is non trivial - to do it you can use the following [technique](https://stackoverflow.com/q/63601330/860099) (discovered by trincot) - for example: `"truefalse".replace("true","1")` can be written as follows:
+Calling a method with more than one argument is non trivial - to do it you can use the following [technique](https://stackoverflow.com/q/63601330/860099) (discovered by trincot) - for example: 
+
+calling string method `"truefalse".replace("true","1")` can be written as `["true", "1"].reduce("".replace.bind("truefalse"))` and finally:
 
 ```js
 ["true"]["concat"]("1")["reduce"](""["replace"]["bind"]("truefalse"))
 ```
 
-### Calling method with more than one argument in "flow way"
+calling array method `[1,2,3].slice(1,2)` can be written as `[1,2].reduce([].slice.bind([1,2,3]))` and finally:
+
+```js
+[1]["concat"](2)["reduce"]([]["slice"]["bind"]([1,2,3]))
+```
+
+
+### Calling string method with more than one argument in "flow way"
+
+To be able to call a method (with multiple arguments) in right side on results of previous method you can use this [technique](https://stackoverflow.com/q/63604058/860099) (discovered by trincot) - for example: `"truefalse".replace("true","1").replace("false","0")` can be written as 
+
+```js
+"truefalse"
+    .split().concat([["true", "1"]]).reduce("".replace.apply.bind("".replace))
+    .split().concat([["false", "0"]]).reduce("".replace.apply.bind("".replace))
+``` 
 
-To be able to call a method (with multiple arguments) in right side on results of previous method you can use this [technique](https://stackoverflow.com/q/63604058/860099) (discovered by trincot) - for example: `"truefalse".replace("true","1").replace("false","0")` can be written as follows:
+and finally:
 
 ```js
 "truefalse"