From a0493c47336294e867fcb5f7313b5bc60eb3a256 Mon Sep 17 00:00:00 2001 From: tiry79 Date: Fri, 7 Apr 2023 13:17:43 +0200 Subject: [PATCH] remove duplicates --- index.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 57e9b15..6fc9757 100644 --- a/index.js +++ b/index.js @@ -203,8 +203,24 @@ function showImages(word) { var now_count = tmp_tabl.length; + var tmp2_tabl = []; + tmp_tabl.forEach((element) => { + if (!tmp2_tabl.includes(element)) { + tmp2_tabl.push(element); + } + }); + tmp_tabl = tmp2_tabl; + + while (now_count < tocount){ - tmp_tabl.push(getRandomElement(data_tabl)); + var hasORiginal = false; + while(!hasORiginal){ + var newthing = getRandomElement(data_tabl); + if (!tmp_tabl.includes(newthing)){ + tmp_tabl.push(newthing); + hasORiginal = true; + } + } now_count++; }