From 7e6970b9e4c04c4dd6ddabb50b77b715e7cbaf9b Mon Sep 17 00:00:00 2001 From: Bladymir Tellez Date: Sun, 23 Aug 2020 11:53:07 -0500 Subject: [PATCH] Implement while --- index.html | 5 +++++ scripts/library.js | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/index.html b/index.html index df1992a..fe16f62 100644 --- a/index.html +++ b/index.html @@ -1214,6 +1214,11 @@ function Library (client) { this.not = (a) => { return !a } + this.while = (fn, action) => { + while (fn()) { + action() + } + } this.each = (arr, fn) => { // Run a function for each element in a list. for (let i = 0; i < arr.length; i++) { const arg = arr[i] diff --git a/scripts/library.js b/scripts/library.js index 168c499..5e0600b 100644 --- a/scripts/library.js +++ b/scripts/library.js @@ -421,6 +421,12 @@ function Library (client) { // Arrays + this.while = (fn, action) => { + while (fn()) { + action() + } + } + this.each = (arr, fn) => { // Run a function for each element in a list. for (let i = 0; i < arr.length; i++) { const arg = arr[i]