├── .editorconfig ├── .gitignore ├── .npmrc ├── .travis.yml ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── src ├── index.js ├── locale │ ├── ar.js │ ├── bg.js │ ├── cz.js │ ├── de.js │ ├── el.js │ ├── en.js │ ├── es.js │ ├── fr.js │ ├── id.js │ ├── index.js │ ├── it.js │ ├── nl.js │ ├── pt.js │ ├── ru.js │ ├── sr.js │ ├── ua.js │ └── zh_cn.js ├── options.js └── store │ ├── ar.js │ ├── bg.js │ ├── cz.js │ ├── de.js │ ├── el.js │ ├── en.js │ ├── es.js │ ├── fr.js │ ├── id.js │ ├── index.js │ ├── it.js │ ├── nl.js │ ├── pt.js │ ├── ru.js │ ├── sr.js │ ├── ua.js │ └── zh_cn.js └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,.*rc,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "node" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Ademola Adegbuyi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | array-explorer-cli 3 |

4 |

5 | Array Explorer CLI 6 | npm travis 7 |

8 |

Find the array method you need without digging through the docs.

9 | 10 | ## Installation 11 | 12 | ```sh 13 | npm i -g array-explorer-cli 14 | ``` 15 | 16 | ## Usage 17 | 18 | Open your CLI and type: 19 | ```sh 20 | array-explorer 21 | ``` 22 | or 23 | ```sh 24 | arr-explorer 25 | ``` 26 | and feel the magic :star: 27 | 28 | array-explorer-cli 29 | 30 | You should also check out [Object Explorer CLI](https://github.com/ooade/object-explorer-cli) 31 | 32 | ## Available Options 33 | 34 | - **-help** - displays help 35 | - **-lang=\ | -l \** - displays array-explorer in the specified language code 36 | 37 | ## List of Available Languages 38 | 39 | | Short Code | Language | 40 | | - | - | 41 | |ar|Arabic| 42 | |bg|Bulgarian| 43 | |cz|Czech| 44 | |de|German| 45 | |el|Greek| 46 | |en|English(Default)| 47 | |es|Spanish| 48 | |fr|French| 49 | |id|Indonesian| 50 | |it|Italian| 51 | |nl|Dutch| 52 | |pt|Portuguese| 53 | |ru|Russian| 54 | |sr|Serbian| 55 | |ua|Ukrainian| 56 | |zh_cn|Chinese (Simplified)| 57 | 58 | Create an issue to add more :tada: 59 | 60 | ## Aknowledgements 61 | Thanks to [Sarah Drasner](https://github.com/sdras). She created the [array-explorer](https://github.com/sdras/array-explorer) web version which you could visit using https://sdras.github.io/array-explorer/ 62 | 63 | ## Contributions 64 | Feel free to contribute. 65 | 66 | ## License 67 | MIT 68 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "array-explorer-cli", 3 | "version": "0.2.0", 4 | "description": 5 | "CLI Tool to help find the array method you need without digging through the docs", 6 | "main": "./src/index.js", 7 | "author": "Ademola Adegbuyi ", 8 | "bin": { 9 | "array-explorer": "./src/index.js", 10 | "arr-explorer": "./src/index.js" 11 | }, 12 | "scripts": { 13 | "test": "node ./test.js | tap-spec" 14 | }, 15 | "license": "MIT", 16 | "dependencies": { 17 | "chalk": "^2.3.2", 18 | "clear": "^0.1.0", 19 | "figlet": "^1.2.0", 20 | "inquirer": "^5.1.0", 21 | "minimist": "^1.2.0" 22 | }, 23 | "devDependencies": { 24 | "tap-spec": "^4.1.1", 25 | "tape": "^4.9.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const inquirer = require('inquirer') 4 | const figlet = require('figlet') 5 | const clear = require('clear') 6 | const chalk = require('chalk') 7 | const argv = require('minimist')(process.argv.slice(2)) 8 | 9 | clear() 10 | 11 | const lang = 12 | typeof argv.lang === 'string' 13 | ? argv.lang 14 | : typeof argv.l === 'string' ? argv.l : 'en' 15 | 16 | const help = argv.help || argv.h || argv._[0] === 'help' 17 | 18 | console.log(figlet.textSync('[ ] Explorer')) 19 | 20 | if (help) { 21 | const countryCodeWithLanguage = `|ar|Arabic| 22 | |bg|Bulgarian| 23 | |cz|Czech| 24 | |de|German| 25 | |el|Greek| 26 | |en|English(Default)| 27 | |es|Spanish| 28 | |fr|French| 29 | |id|Indonesian| 30 | |it|Italian| 31 | |nl|Dutch| 32 | |pt|Portuguese| 33 | |ru|Russian| 34 | |sr|Serbian| 35 | |ua|Ukrainian| 36 | |zh_cn|Chinese (Simplified)|` 37 | 38 | console.log() 39 | 40 | console.log( 41 | '- A CLI package to help figure out what JavaScript array method would be best to use at any given time' 42 | ) 43 | 44 | console.log() 45 | 46 | console.log( 47 | `${chalk.bold('usage:')} array-explorer [help] [-h | --help] ` 48 | ) 49 | 50 | console.log() 51 | 52 | console.log(' can be one of the following:') 53 | 54 | console.log() 55 | 56 | countryCodeWithLanguage 57 | .split('\n') 58 | .map(s => s.split('|').slice(1, 3)) 59 | .map(([code, lang]) => { 60 | console.log(`- ${chalk.bold(code)} - ${chalk.hex('#888888')(lang)}`) 61 | }) 62 | 63 | console.log() 64 | 65 | console.log('Example: array-explorer --lang es') 66 | 67 | console.log() 68 | 69 | return 70 | } 71 | 72 | let questions = require('./options')(lang) 73 | let state = require('./store')[lang].state 74 | 75 | console.log() 76 | 77 | inquirer.prompt(questions).then(answers => { 78 | let answer = Object.keys(answers).filter(answer => answer !== 'init') 79 | 80 | // This arr stores the container of our real answer 81 | let arr = [] 82 | 83 | // if 2, it's an obj, walk through it 84 | if (answer.length === 2) { 85 | arr = state[answer[0]][answer[1]] 86 | } else { 87 | arr = state[answer[0]] 88 | } 89 | 90 | const objValue = Object.keys(answers).map(answer => answers[answer]) 91 | 92 | const value = arr.filter(item => item.shortDesc === objValue.slice(-1)[0])[0] 93 | 94 | const formatCode = str => 95 | str 96 | .replace(/\n+\t+/g, '\t') 97 | .replace(/
/g, '\n') 98 | .replace(/\\ \;\ \;\<\/span\>/g, '\t') 99 | .replace(/\]*\>(.*?)\<\/span\>/g, (_, s) => chalk.hex('#888')(s)) 100 | 101 | const formatDesc = str => 102 | str.replace(/\(.*?)\<\/code\>/g, (_, s) => chalk.bold(s)) 103 | 104 | console.log() 105 | 106 | console.log(chalk.green.bold(`Array.${value.name}()`)) 107 | 108 | console.log() 109 | 110 | console.log('- ' + formatDesc(value.desc)) 111 | 112 | console.log() 113 | 114 | console.log(chalk.bold('USAGE:')) 115 | 116 | console.log(chalk.hex('#aeded4')('\tlet arr = [5, 1, 8]')) 117 | 118 | console.log('\t' + chalk.hex('#aeded4')(formatCode(value.example))) 119 | 120 | console.log() 121 | 122 | console.log( 123 | chalk.bold('OUTPUT:\t') + chalk.hex('#ecc2a4')(formatCode(value.output)) 124 | ) 125 | 126 | console.log() 127 | 128 | console.log( 129 | chalk.bold('READ MORE: ') + 130 | 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/' + 131 | value.name 132 | ) 133 | 134 | console.log() 135 | }) 136 | -------------------------------------------------------------------------------- /src/locale/ar.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'لدي مجموعة، أود', 3 | findMethod: 'أحاول أن أجد', 4 | methodOptions: 'أنا بحاجة لــ', 5 | methodTypes: { 6 | add: 'إضافة', 7 | remove: 'إزالة', 8 | find: 'بحث', 9 | 'iterate by': 'يتكرر من قبل', 10 | string: ' سلسلة' 11 | }, 12 | singleItem: 'عنصر واحد', 13 | manyItems: 'واحد أو العديد من العناصر', 14 | primaryOptions: [ 15 | 'إضافة عناصر أو صفائف أخرى', 16 | 'إزالة العناصر', 17 | 'العثور على العناصر', 18 | 'المشي على العناصر', 19 | 'إرجاع سلسلة', 20 | 'ترتيب مصفوفة', 21 | 'شيء آخر' 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/locale/bg.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Имам масив, бих искал да', // I have an array, I would like to 3 | findMethod: 'Опитвам се да намеря', // I'm trying to find 4 | methodOptions: 'Tрябва да', 5 | methodTypes: { 6 | add: 'добавя', 7 | remove: 'премахна', 8 | find: 'намеря', 9 | 'iterate by': 'обходя', 10 | string: 'низ' 11 | }, 12 | singleItem: 'един елемент', // one item 13 | manyItems: 'един или много елементи', // one or many items 14 | primaryOptions: [ 15 | 'добавя елементи или други масиви', // add items or other arrays 16 | 'премахна елементи', // remove items 17 | 'намеря елементи', // find items 18 | 'премина през елементите', // walk over items 19 | 'върна низ', // return a string 20 | 'сортирам масив', // order an array 21 | 'нещо друго' // something else 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/locale/cz.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Mám pole a chci', 3 | findMethod: 'Snažím se najít', 4 | methodOptions: 'Potřebuji', 5 | methodTypes: { 6 | add: 'přidat', 7 | remove: 'odebrat', 8 | find: 'nalézt', 9 | 'iterate by': 'projít pomocí', 10 | string: 'řetězec' 11 | }, 12 | singleItem: 'jeden prvek', 13 | manyItems: 'jeden nebo více prvků', 14 | primaryOptions: [ 15 | 'přidat prvky nebo jiná pole', 16 | 'odebrat prvky', 17 | 'najít prvky', 18 | 'projít prvky', 19 | 'vrátit řetězec', 20 | 'seřadit pole', 21 | 'něco jiného' 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/locale/de.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Ich habe einen Array und würde gerne', //'I have an array, I would like to', 3 | findMethod: 'Ich möchte', // "I'm trying to find" 4 | methodOptions: 'Ich muss', 5 | methodTypes: { 6 | add: '', 7 | remove: '', 8 | find: '', 9 | 'iterate by': '', 10 | string: 'String zurückgeben' 11 | }, 12 | singleItem: 'ein Element finden', // 'one item', 13 | manyItems: 'ein oder mehrere Elemente finden', // 'one or many items', 14 | primaryOptions: [ 15 | 'Elemente oder Arrays hinzufügen', // ich würde gerne i would like to ... add items or other arrays 16 | 'Elemente entfernen', 17 | 'Elemente finden', 18 | 'Elemente durchlaufen', 19 | 'einen String zurückgeben', 20 | 'einen Array sortieren', 21 | 'etwas anderes machen' 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/locale/el.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Έχω έναν πίνακα, θα ήθελα να', 3 | findMethod: 'Προσπαθώ να βρω', 4 | methodOptions: 'Θέλω να', 5 | methodTypes: { 6 | add: 'προσθέσω', 7 | remove: 'αφαιρέσω', 8 | find: 'βρω', 9 | 'iterate by': '', 10 | string: 'αλφαριθμητικό' 11 | }, 12 | singleItem: 'ένα στοιχείο', 13 | manyItems: 'ένα ή περισσότερα στοιχεία', 14 | primaryOptions: [ 15 | 'προσθέσω στοιχεία ή άλλους πίνακες', 16 | 'αφαιρέσω στοιχεία', 17 | 'βρω στοιχεία', 18 | 'διατρέξω τα στοιχεία', 19 | 'επιστρέψω έναν πίνακα', 20 | 'ταξινομήσω τον πίνακα', 21 | 'κάτι διαφορετικό' 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/locale/en.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'I have an array, I would like to', 3 | findMethod: "I'm trying to find", 4 | methodOptions: 'I need to', 5 | methodTypes: { 6 | add: 'add', 7 | remove: 'remove', 8 | find: 'find', 9 | 'iterate by': 'iterate by', 10 | string: 'string' 11 | }, 12 | singleItem: 'one item', 13 | manyItems: 'one or many items', 14 | primaryOptions: [ 15 | 'add items or other arrays', 16 | 'remove items', 17 | 'find items', 18 | 'walk over items', 19 | 'return a string', 20 | 'order an array', 21 | 'something else' 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/locale/es.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Tengo un array, me gustaría', 3 | findMethod: 'Estoy intentando encontrar', 4 | methodOptions: 'Necesito que', 5 | methodTypes: { 6 | add: 'agregar', 7 | remove: 'eliminar', 8 | find: 'buscar', 9 | 'iterate by': 'iterar con', 10 | string: 'Cadena de caracteres' 11 | }, 12 | singleItem: 'un elemento', 13 | manyItems: 'uno o mas elementos', 14 | primaryOptions: [ 15 | 'agregar elementos u otros arrays', 16 | 'eliminar elementos', 17 | 'buscar elementos', 18 | 'pasar entre elementos', 19 | 'devolver una cadena de caracteres', 20 | 'ordenar un array', 21 | 'cualquier otra cosa' 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/locale/fr.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: "J'ai un tableau, je voudrais", 3 | findMethod: "J'essaye de trouver", 4 | methodOptions: "J'ai besoin", 5 | methodTypes: { 6 | add: "d'ajouter", 7 | remove: 'de supprimer', 8 | find: 'de chercher', 9 | 'iterate by': "d'itérer en", 10 | string: 'chaîne de caractères' 11 | }, 12 | singleItem: 'un élément', 13 | manyItems: 'un ou plusieurs éléments', 14 | primaryOptions: [ 15 | 'ajouter des éléments', 16 | 'supprimer des éléments', 17 | 'chercher des éléments', 18 | 'parcourir les éléments', 19 | 'retourner une chaîne de caractères', 20 | 'trier les éléments', 21 | 'faire autre chose' 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/locale/id.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Saya mempunyai array, saya ingin', 3 | findMethod: 'Saya ingin mencari', 4 | methodOptions: 'Saya perlu untuk', 5 | methodTypes: { 6 | add: 'menambah', 7 | remove: 'menghapus', 8 | find: 'menemukan', 9 | 'iterate by': 'melakukan iterasi dengan', 10 | string: 'string' 11 | }, 12 | singleItem: 'sebuah item', 13 | manyItems: 'satu atau banyak item', 14 | primaryOptions: [ 15 | 'menambah item atau array lain', 16 | 'menghilangkan item', 17 | 'menemukan item', 18 | 'melakukan iterasi terhadap item', 19 | 'mengembalikan sebuah string', 20 | 'mengurutkan sebuah array', 21 | 'lainnya' 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/locale/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | ar: require('./ar'), 3 | bg: require('./bg'), 4 | cz: require('./cz'), 5 | de: require('./de'), 6 | en: require('./en'), 7 | fr: require('./fr'), 8 | id: require('./id'), 9 | it: require('./it'), 10 | nl: require('./nl'), 11 | pt: require('./pt'), 12 | ru: require('./ru'), 13 | sr: require('./sr'), 14 | ua: require('./ua'), 15 | zh_cn: require('./zh_cn') 16 | } 17 | -------------------------------------------------------------------------------- /src/locale/it.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Ho un array e vorrei', 3 | findMethod: 'Sto cercando', 4 | methodOptions: 'Voglio', 5 | methodTypes: { 6 | add: 'aggiungere', 7 | remove: 'togliere', 8 | find: 'trovare', 9 | 'iterate by': '', 10 | string: '' 11 | }, 12 | singleItem: 'un elemento', 13 | manyItems: 'uno o più elementi', 14 | primaryOptions: [ 15 | 'aggiungere elementi o altri array', 16 | 'rimuovere elementi', 17 | 'cercare uno o più valori', 18 | 'visitarne gli elementi', 19 | 'generare una stringa', 20 | 'riordinarlo', 21 | "fare qualcos'altro" 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/locale/nl.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Ik heb een array, ik wil graag', 3 | findMethod: 'Ik ben op zoek naar', 4 | methodOptions: 'Ik moet', 5 | methodTypes: { 6 | add: 'toevoegen', 7 | remove: 'verwijderen', 8 | find: 'zoeken', 9 | 'iterate by': 'itereren door', 10 | string: 'string' 11 | }, 12 | singleItem: 'een enkel element', 13 | manyItems: 'een of meerdere elementen', 14 | primaryOptions: [ 15 | 'een element of een andere array toevoegen', 16 | 'elementen verwijderen', 17 | 'elementen zoeken', 18 | 'door elementen heen loopen', 19 | 'een string teruggeven', 20 | 'een array ordenen', 21 | 'iets anders' 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/locale/pt.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Eu tenho um array e gostaria de:', 3 | findMethod: 'Eu estou tentando encontrar', 4 | methodOptions: 'Eu preciso', 5 | methodTypes: { 6 | add: 'adicionar', 7 | remove: 'remover', 8 | find: 'procurar', 9 | 'iterate by': 'iterar', 10 | string: 'string' 11 | }, 12 | singleItem: 'um item', 13 | manyItems: 'um ou mais itens', 14 | primaryOptions: [ 15 | 'adicionar um item ou outro array', 16 | 'remover itens', 17 | 'procurar itens', 18 | 'iterar sobre os itens', 19 | 'retornar uma string', 20 | 'ordernar os itens', 21 | 'nenhuma das opções' 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /src/locale/ru.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'У меня есть массив, я хотел бы', 3 | findMethod: 'Я пытаюсь найти', 4 | methodOptions: 'Мне нужно', 5 | methodTypes: { 6 | add: 'добавить', 7 | remove: 'удалить', 8 | find: 'найти', 9 | 'iterate by': 'пройти', 10 | string: 'строка' 11 | }, 12 | singleItem: 'один элемент', 13 | manyItems: 'один или более элементов', 14 | primaryOptions: [ 15 | 'добавить элементы или другие массивы', 16 | 'удалить элементы', 17 | 'найти элементы', 18 | 'пройти по элементам', 19 | 'получить строку', 20 | 'упорядочить массив', 21 | 'другое' 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/locale/sr.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'Imam niz, želeo/la bih da', 3 | findMethod: 'Pokušavam da pronađem', 4 | methodOptions: 'Želeo/la bih', 5 | methodTypes: { 6 | add: 'da dodam', 7 | remove: 'da uklonim', 8 | find: 'da pronađem', 9 | 'iterate by': 'iteriram po', 10 | string: 'string' 11 | }, 12 | singleItem: 'jednom elementu', 13 | manyItems: 'jednom ili više elemenata', 14 | primaryOptions: [ 15 | 'dodam elemente ili druge nizove', 16 | 'uklonim elemente', 17 | 'pronađem elemente', 18 | 'pređem preko elemenata', 19 | 'vratim string', 20 | 'sortiram niz', 21 | 'nešto drugo' 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/locale/ua.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: 'У мене є масив, я хотів би', 3 | findMethod: 'Я намагаюсь знайти', 4 | methodOptions: 'Мені потрібно', 5 | methodTypes: { 6 | add: 'додати', 7 | remove: 'remove', 8 | find: 'видалити', 9 | 'iterate by': 'ітеруватися', 10 | string: 'стрічка' 11 | }, 12 | singleItem: 'один елемент', 13 | manyItems: 'один чи більше елементів', 14 | primaryOptions: [ 15 | 'додати елементи або інші масиви', 16 | 'видалити елементи', 17 | 'знайти елементи', 18 | 'пройти по елементам', 19 | 'повернути рядок', 20 | 'сортувати масив', 21 | 'інше' 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/locale/zh_cn.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | firstMethod: '我有一个数组,我想', 3 | findMethod: '我想查找', 4 | methodOptions: '我需要', 5 | methodTypes: { 6 | add: '添加', 7 | remove: '移除', 8 | find: '查找', 9 | 'iterate by': '', 10 | string: '字符串' 11 | }, 12 | singleItem: '一个元素', 13 | manyItems: '一个或多个元素', 14 | primaryOptions: [ 15 | '添加元素或别的数组', 16 | '移除元素', 17 | '查找元素', 18 | '对每个元素进行操作', 19 | '返回字符串', 20 | '对数组排序', 21 | '其它' 22 | ] 23 | // other text can be added here 24 | } 25 | -------------------------------------------------------------------------------- /src/options.js: -------------------------------------------------------------------------------- 1 | const locale = require('./locale') 2 | 3 | // Maps method to primary option index 4 | const mapMethodToIndex = { 5 | adding: 0, 6 | removing: 1, 7 | string: 4, 8 | ordering: 5, 9 | other: 6, 10 | iterate: 3, 11 | find: 2 12 | } 13 | 14 | function singleOption(type, name, message, choices, when) { 15 | return { 16 | type, 17 | name, 18 | message, 19 | choices, 20 | when 21 | } 22 | } 23 | 24 | function generateOptions(lang) { 25 | let localeLang = locale[lang] 26 | 27 | if (!Object.keys(locale).some(l => l === lang)) { 28 | console.log() 29 | 30 | console.log('Language not found!') 31 | 32 | console.log() 33 | 34 | console.log( 35 | 'Type `array-explorer help` to see list of available languages' 36 | ) 37 | 38 | console.log() 39 | 40 | process.exit(1) 41 | } 42 | 43 | const state = require('./store')[lang].state 44 | 45 | // This has the localMethods names 46 | const localeMethods = Object.keys(state).slice(1) 47 | 48 | // The first option that is shown to users 49 | const firstOption = [{ 50 | type: 'list', 51 | name: 'init', 52 | message: localeLang.firstMethod, 53 | choices: localeLang.primaryOptions 54 | }] 55 | 56 | // Picks the methodVerbs 57 | const methodVerbs = { 58 | adding: localeLang.methodTypes.add, 59 | removing: localeLang.methodTypes.remove, 60 | string: '', 61 | ordering: '', 62 | other: '', 63 | iterate: localeLang.methodTypes['iterate by'], 64 | find: localeLang.findMethod 65 | } 66 | 67 | const options = localeMethods.map(method => { 68 | const methodIndex = mapMethodToIndex[method] 69 | const methodVerb = methodVerbs[method] 70 | 71 | let methodOptions = localeLang.methodOptions 72 | let choices 73 | 74 | if (method === 'find') { 75 | choices = [localeLang.singleItem, localeLang.manyItems] 76 | methodOptions = localeLang.findMethod 77 | } else { 78 | choices = state[method].map(s => s.shortDesc) 79 | } 80 | 81 | return singleOption( 82 | 'list', 83 | method.trim(), 84 | (method === 'find' ? 85 | methodVerb : 86 | methodOptions + ' ' + methodVerb 87 | ).trim(), 88 | choices, 89 | answers => answers.init === localeLang.primaryOptions[methodIndex] 90 | ) 91 | }) 92 | 93 | return firstOption.concat( 94 | options.concat( 95 | Object.keys(state.find).map(method => { 96 | const mapFindOptions = { 97 | single: localeLang.singleItem, 98 | many: localeLang.manyItems 99 | } 100 | 101 | return singleOption( 102 | 'list', 103 | method.trim(), 104 | (localeLang.methodOptions + ' ' + localeLang.methodTypes.find).trim(), 105 | state.find[method].map(s => s.shortDesc), 106 | answers => answers.find === mapFindOptions[method] 107 | ) 108 | }) 109 | ) 110 | ) 111 | } 112 | 113 | module.exports = generateOptions 114 | -------------------------------------------------------------------------------- /src/store/ar.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: 'عنصر أو أكثر للمصفوفة', 8 | desc: 'تضيف و/أو تحذف عناصر من المصفوفة.', 9 | example: `arr.splice(2, 0, 'tacos');
10 | console.log(arr);`, 11 | output: `[5, 1, 'tacos', 8]` 12 | }, 13 | { 14 | name: 'push', 15 | shortDesc: 'عناصر إلى نهاية المصفوفة', 16 | desc: 17 | 'إضافة عنصر أو أكثر إلى نهاية المصفوفة وتعيد الطول الجديد للمصفوفة.', 18 | example: `arr.push(2);
19 | console.log(arr);`, 20 | output: '[5, 1, 8, 2]' 21 | }, 22 | { 23 | name: 'unshift', 24 | shortDesc: 'عناصر إلى بداية المصفوفة', 25 | desc: 26 | 'إضافة عنصر أو أكثر إلى بداية المصفوفة وتعيد الطول الجديد للمصفوفة.', 27 | example: `arr.unshift(2, 7);
28 | console.log(arr);`, 29 | output: '[2, 7, 5, 1, 8]' 30 | }, 31 | { 32 | name: 'concat', 33 | shortDesc: 'هذه المصفوفة إلى مصفوفة أو أكثر و/أو قيمة أو أكثر', 34 | desc: 35 | 'تعيد المصفوفة المكونة من هذه المصوفة مع مصفوفة أو أكثر و/أو قيمة أكثر الأخرى.', 36 | example: `let arr2 = ['a', 'b', 'c'];
37 | let arr3 = arr.concat(arr2);
38 | console.log(arr3);`, 39 | output: `[5, 1, 8, 'a', 'b', 'c']` 40 | } 41 | ], 42 | removing: [ 43 | { 44 | name: 'splice', 45 | shortDesc: 'عنصر أو أكثر من المصفوفة', 46 | desc: 'تضيف و/أو تحذف عناصر من المصفوفة.', 47 | example: `arr.splice(2, 1);
48 | console.log(arr);`, 49 | output: `[5, 1]` 50 | }, 51 | { 52 | name: 'pop', 53 | shortDesc: 'العنصر الأخير في المصفوفة', 54 | desc: 'تحذف العنصر الأخير في المصفوفة وتعيد هذا العنصر.', 55 | example: `arr.pop();
56 | console.log(arr);`, 57 | output: `[5, 1]` 58 | }, 59 | { 60 | name: 'shift', 61 | shortDesc: 'العنصر الأول من المصفوفة', 62 | desc: 'تحذف العنصر الأول من المصفوفة وتعيد هذا العنصر.', 63 | example: `arr.shift();
64 | console.log(arr);`, 65 | output: `[1, 8]` 66 | }, 67 | { 68 | name: 'slice', 69 | shortDesc: 70 | 'عنصر أو أكثر من المصفوفة للاستخدام ، تاركة المصفوفة الأصلية كما هي', 71 | desc: 72 | 'الدالة slice() تعيد نسخة مصغرة لجزء من مصفوفة إلى عنصر مصفوفة جديد . بإمكانك إما تحديد العنصر الأخير ( حيث أن العنصر الأول الافتراضي سيكون صفر ) أو بإمكانك تحديد البداية والنهاية, مفصولين بفاصلة , comma-separated. المصفوفة الأصلية لن يتم تعديلها.', 73 | example: `let slicedArr = arr.slice(1);
74 | console.log(arr);
75 | console.log(slicedArr);`, 76 | output: `[5, 1, 8]
77 | [1, 8]` 78 | } 79 | ], 80 | string: [ 81 | { 82 | name: 'join', 83 | shortDesc: 'دمج جميع عناصر المصفوفة في سلسلة نصية واحدة', 84 | desc: `دمج جميع عناصر المصفوفة في سلسلة نصية . بإمكانك دمجهم مع بعض كماهم أو مع فاصل بينهم, elements.join(' - 85 | ') تعطيك foo-bar`, 86 | example: `console.log(arr.join());`, 87 | output: `"5,1,8"` 88 | }, 89 | { 90 | name: 'toString', 91 | shortDesc: 'تعيد سلسلة نصية تمثل هذه المصفوفة.', 92 | desc: 'تعيد سلسلة نصية تمثل المصفوفة وعناصرها.', 93 | example: `console.log(arr.toString());`, 94 | output: `"5,1,8"` 95 | }, 96 | { 97 | name: 'toLocaleString', 98 | shortDesc: 'تعيد سلسلة نصية (محلية- تمثل البلد الحالي ) تمثل المصفوفة.', 99 | desc: 100 | 'هذه الدالة فيها قليل من الجنون. تعيد سلسلة نصية (محلية- تمثل البلد الحالي ) تمثل المصفوفة وعناصرها. هذه الدالة مفيدة للتواريخ والعملات وكذلك بعض الاختصارات المحلية الغريبة, لذلك يستحسن مراجعة التوثيق الخاص بها', 101 | example: `let date = [new Date()];
102 | arr.toLocaleString();
103 | date.toLocaleString();
104 | console.log(arr, date);`, 105 | output: `"5,1,8 12/26/2017, 6:54:49 م"` 106 | } 107 | ], 108 | ordering: [ 109 | { 110 | name: 'reverse', 111 | shortDesc: 'تعكس ترتيب عناصر المصفوفة', 112 | desc: 113 | 'تعكس ترتيب عناصر المصفوفة بمكانهم - بحيث الأول يصبح الأخير والأخير يصبح الأول.', 114 | example: `arr.reverse();
115 | console.log(arr);`, 116 | output: `[8, 1, 5]` 117 | }, 118 | { 119 | name: 'sort', 120 | shortDesc: 'ترتيب عناصر المصفوفة', 121 | 122 | desc: `ترتب عناصر المصفوفة المحددة وترجع مصفوفة مرتبة.
123 |
124 | ملاحطة مهمة: إذا لم يتم كتابة دالة الترتيب ، سيتم ترتيب العناصر عن طريق تحويلهم إلى سلاسل ومقارنة على أساس ترتيبهم ضمن الـ Unicode الخاص بهم.على سبيل المثال، "Banana" تأتي قبل "cherry". في الترتيب بالنسبة للأرقام، فإن 9 تأتي قبل 80 ، وذلك لأنه تم تحويل الأرقام إلى سلاسل نصية ، و "80" تأتي قبل "9" في ترتيب الرموز ضمن الـ Unicode . التوثيق في الكثير من المعلومات للتوضيح.`, 125 | example: `arr.sort();
126 | console.log(arr);`, 127 | output: `[1, 5, 8]` 128 | } 129 | ], 130 | other: [ 131 | { 132 | name: 'length', 133 | shortDesc: 'معرفة طول المصفوفة', 134 | desc: 'تعيد عدد العناصر في هذه المصفوفة.', 135 | example: `console.log(arr.length);`, 136 | output: `3` 137 | }, 138 | { 139 | name: 'fill', 140 | shortDesc: 'تعبية جميع عناصر المصفوفة بقيمة ثابتة', 141 | desc: 142 | 'تقوم بتعبئة جميع عناصر المصفوفة ابتداءً من عنوان البداية إلى عنوان النهاية بقيم .', 143 | example: `arr.fill(2);
144 | console.log(arr);`, 145 | output: `[2, 2, 2]` 146 | }, 147 | { 148 | name: 'copyWithin', 149 | shortDesc: 'نسخ سلسلة من عناصر المصفوفة ضمن المصفوفة.', 150 | desc: 151 | 'تقوم بنسخ سلسلة من عناصر المصوفة ضمن المصفوفة نفسها . بإمكانك تحديد العنصر الأخير فقط ( حيث العنصر الأول سيكون الافتراضي صفر ) أو بإمكانك تحديد العنصر الأول والأ×ير مفصولين بفاصلة , comma-separated.', 152 | example: `arr.copyWithin(1);
153 | console.log(arr);`, 154 | output: `[5, 5, 1]` 155 | } 156 | ], 157 | iterate: [ 158 | { 159 | name: 'forEach', 160 | shortDesc: 'تنفيذ دالة سأقوم بإنشاء (for each) للعنصر', 161 | desc: 162 | 'دالة الـ forEach() تقوم بتنفيذ دالة معينة مرة واحد لكل من عناصر المصفوفة.', 163 | example: `arr.forEach((element) => {
164 |   console.log(element)
165 | });`, 166 | output: `5
167 | 1
168 | 8` 169 | }, 170 | { 171 | name: 'map', 172 | shortDesc: 173 | ' تقوم بإنشاء مصفوفة جديدة من كل عنصر بإستخدام دالة أقوم بإنشاءها', 174 | desc: 175 | 'تقوم بإنشاء مصفوفة جديدة بإستخدام النتيجة الراجعة من استدعاء دالة معينة على جميع العناصر في هذه المصفوفة.', 176 | example: `let map = arr.map(x => x + 1);
177 | console.log(map);`, 178 | output: `[6, 2, 9]` 179 | }, 180 | { 181 | name: 'entries', 182 | shortDesc: 'تنش عنصر تكرار (iterator object)', 183 | desc: 184 | 'تعيد عنصر تكرار جديد للمصفوفة والذي يحتوي على أزواج الـ key/value لكل عنوان (index) في هذه المصفوفة. توجد استخدامات كثيرة للتكرارات (iterators), وكذلك دوال أخرى تستخدم معها, مثل values و keys', 185 | example: `let iterator = arr.entries();
186 | console.log(iterator.next().value);`, 187 | output: `[0, 5]
188 | // the 0 is the index,
189 | // the 5 is the first number` 190 | } 191 | ], 192 | find: { 193 | single: [ 194 | { 195 | name: 'includes', 196 | shortDesc: 'تعيد إذا كان عنصر معين موجود', 197 | desc: 198 | 'تقرر فيما إذا كانت مصفوفة معينة تحتوي على عنصر معين ، وتعيد true أو false بما يناسب الحالة.', 199 | example: `console.log(arr.includes(1));`, 200 | output: `true` 201 | }, 202 | { 203 | name: 'indexOf', 204 | shortDesc: 'العنوان الأول لعنصر معين', 205 | desc: 206 | 'تعيد أول عنوان حيث يمكن العثور على عنصر معين في مصفوفة, أو -1 إذا لم يتم العثور عليه.', 207 | example: `console.log(arr.indexOf(5));`, 208 | output: `0` 209 | }, 210 | { 211 | name: 'lastIndexOf', 212 | shortDesc: 'العنوان الأخير لعنصر معين', 213 | desc: 214 | 'تعيد آخر ( أكبر ) عنوان لعنصر معين ضمن مصفوفة مساوي للقيمة المحددة , أو -1 إذا كان غير موجود.', 215 | example: `console.log(arr.lastIndexOf(5));`, 216 | output: `0` 217 | }, 218 | { 219 | name: 'find', 220 | shortDesc: 'أول عنصر يطابق شرط معين', 221 | desc: 222 | 'تعيد القيمة التي تم العثور عليها في المصوفة ، إذا وجد عنصر يطابق لدالة الفحص المعينة أو غير معرف ( undefined ) إذا لم يتم العثور عليه. مشابهة لـ findIndex(), ولكنها تعيد العنصر عوضا عن العنوان (index).', 223 | example: `let isTiny = (el) => el < 2;
224 | console.log(arr.find(isTiny));`, 225 | output: `1` 226 | }, 227 | { 228 | name: 'findIndex', 229 | shortDesc: 'أول عنوان (index) للعصر الذي يطابق شرط معين', 230 | desc: 231 | 'تعيد أول عنوان (index) لعنصر معين في مصفوفة إذا طابق دالة الفحص المعينة . أو -1 إذا لم يطابق. مماثلة لـ find(), ولكنها تعيد العنوان (index) عوضا عن العنصر.', 232 | example: `let isBig = (el) => el > 6;
233 | console.log(arr.findIndex(isBig));`, 234 | output: `2` 235 | }, 236 | { 237 | name: 'reduce', 238 | shortDesc: 'قيمة بواسطة تصغير المصفوفة ، من البداية للنهاية', 239 | desc: 240 | 'تنفيذ دالة على مراكم وكل قيمة في المصفوفة ( من اليسار إلى اليمين ) لتقليصها إلى قيمة واحدة.', 241 | example: `let reducer = (a, b) => a + b;
242 | console.log(arr.reduce(reducer));`, 243 | output: `14` 244 | }, 245 | { 246 | name: 'reduceRight', 247 | shortDesc: 'قيمة بواسطة تصغير المصفوفة ، من النهاية إلى البداية', 248 | desc: 249 | 'تنفيذ دالة على مراكم وكل قيمة في المصفوفة ( من اليمين إلى اليسار ) لتقليصها إلى قيمة واحدة.', 250 | example: `[arr, [0, 1]].reduceRight((a, b) => {
251 |   return a.concat(b)
252 | }, [])`, 253 | output: `[0, 1, 5, 1, 8]` 254 | } 255 | ], 256 | many: [ 257 | { 258 | name: 'filter', 259 | shortDesc: 'قيم بناء على شرط أقوم بتحديده', 260 | desc: 261 | 'تعيد مصفوفة جديد تحتوى على جميع عناصر هذه المصفوفة التي نتيجة دالة الترشيح true.', 262 | example: `let filtered = arr.filter(el => el > 4);
263 | console.log(filtered)`, 264 | output: `[5, 8]` 265 | }, 266 | { 267 | name: 'every', 268 | shortDesc: 'فيما إذا كانت جميع العناصر تطابق شرط معين أو لا', 269 | desc: 'تعيد (true) إذا كانت جميع القيم تطابق دالة الفحص.', 270 | example: `let isSmall = (el) => el < 10;
271 | console.log(arr.every(isSmall));`, 272 | output: `true` 273 | }, 274 | { 275 | name: 'some', 276 | shortDesc: 'فيما إذا طابق عنصر واحد على الأقل شرط معين أو لا', 277 | desc: 278 | 'تعيد (true) إذا طابق على الأقل عنصر واحد من هذه المصفوفة لدالة الفحص.', 279 | example: `let biggerThan4 = (el) => el > 4;
280 | console.log(arr.some(biggerThan4));`, 281 | output: `true` 282 | } 283 | ] 284 | } 285 | } 286 | } 287 | -------------------------------------------------------------------------------- /src/store/bg.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: 'елемент(и) в масив', 8 | desc: 'Добавя и/или премахва елементи от масив.', 9 | example: `arr.splice(2, 0, 'tacos');
10 | console.log(arr);`, 11 | output: `[5, 1, 'tacos', 8]` 12 | }, 13 | { 14 | name: 'push', 15 | shortDesc: 'елементи в края на масива', 16 | desc: 17 | 'Добавя един или повече елементи в края на масива и връща новата дължина на масива.', 18 | example: `arr.push(2);
19 | console.log(arr);`, 20 | output: '[5, 1, 8, 2]' 21 | }, 22 | { 23 | name: 'unshift', 24 | shortDesc: 'елементи в началото на масива', 25 | desc: 26 | 'Добавя един или повече елементи в началото на масива и връща новата дължина на масива.', 27 | example: `arr.unshift(2, 7);
28 | console.log(arr);`, 29 | output: '[2, 7, 5, 1, 8]' 30 | }, 31 | { 32 | name: 'concat', 33 | shortDesc: 'този масив в друг масив(и) и/или стойност(и)', 34 | desc: 35 | 'Връща нов масив, съставен от този масив, свързан с друг масив(и) и/или стойност(и).', 36 | example: `let arr2 = ['a', 'b', 'c'];
37 | let arr3 = arr.concat(arr2);
38 | console.log(arr3);`, 39 | output: `[5, 1, 8, 'a', 'b', 'c']` 40 | } 41 | ], 42 | removing: [ 43 | { 44 | name: 'splice', 45 | shortDesc: 'елемент(и) от масив', 46 | desc: 'Добавя и/или премахва елементи от масив.', 47 | example: `arr.splice(2, 1);
48 | console.log(arr);`, 49 | output: `[5, 1]` 50 | }, 51 | { 52 | name: 'pop', 53 | shortDesc: 'последният елемент на масива', 54 | desc: 'Премахва последния елемент от масив и връща този елемент.', 55 | example: `arr.pop();
56 | console.log(arr);`, 57 | output: `[5, 1]` 58 | }, 59 | { 60 | name: 'shift', 61 | shortDesc: 'първият елемент на масива', 62 | desc: 'Премахва първия елемент от масив и връща този елемент.', 63 | example: `arr.shift();
64 | console.log(arr);`, 65 | output: `[1, 8]` 66 | }, 67 | { 68 | name: 'slice', 69 | shortDesc: 70 | 'едно или повече елементи за употреба, оставяйки масива, както е', 71 | desc: 72 | 'Методът slice() връща плитко копие на част от масив в нов обект от масив. Можете да посочите или само крайния елемент (откъдето започва да е по подразбиране до нула) или и началото, и края, разделени със запетая. Оригиналният масив няма да бъде променен.', 73 | example: `let slicedArr = arr.slice(1);
74 | console.log(arr);
75 | console.log(slicedArr);`, 76 | output: `[5, 1, 8]
77 | [1, 8]` 78 | } 79 | ], 80 | string: [ 81 | { 82 | name: 'join', 83 | shortDesc: 'присъединете всички елементи на масива към низ', 84 | desc: `Присъединява всички елементи на масива към низ. Можете да ги присъедините заедно, както е или с нещо между тях, elements.join ('-') ви дава foo-bar`, 85 | example: `console.log(arr.join());`, 86 | output: `"5,1,8"` 87 | }, 88 | { 89 | name: 'toString', 90 | shortDesc: 'връща низ, представляващ масива', 91 | desc: 'Връща низ, представляващ масива и неговите елементи.', 92 | example: `console.log(arr.toString());`, 93 | output: `"5,1,8"` 94 | }, 95 | { 96 | name: 'toLocaleString', 97 | shortDesc: 'връща локализиран низ, представляващ масива', 98 | desc: 99 | 'Това е малко вълшебство. Връща локализиран низ, представляващ масива и неговите елементи. Това е много полезно за дати и валута и има някои странни местни абстракции, така че най-добре да се консултирате с документите, когато го използвате.', 100 | example: `let date = [new Date()];
101 | const arrString = arr.toLocaleString();
102 | const dateString = date.toLocaleString();
103 | console.log(arrString, dateString);`, 104 | output: `"5,1,8 12/26/2017, 6:54:49 PM"` 105 | } 106 | ], 107 | ordering: [ 108 | { 109 | name: 'reverse', 110 | shortDesc: 'обръщане на реда на масива', 111 | desc: 112 | 'Обръща реда на елементите на масив на място - първият става последният и последният става първият.', 113 | example: `arr.reverse();
114 | console.log(arr);`, 115 | output: `[8, 1, 5]` 116 | }, 117 | { 118 | name: 'sort', 119 | shortDesc: 'сортирайте елементите на масива', 120 | desc: 'Сортира елементите на масив на място и връща масива.', 121 | example: `arr.sort();
122 | console.log(arr);`, 123 | output: `[1, 5, 8]` 124 | } 125 | ], 126 | other: [ 127 | { 128 | name: 'length', 129 | shortDesc: 'намерете дължината на масива', 130 | desc: 'Връща броя елементи в този масив.', 131 | example: `console.log(arr.length);`, 132 | output: `3` 133 | }, 134 | { 135 | name: 'fill', 136 | shortDesc: 'попълнете всички елементи на масива със статична стойност', 137 | desc: 138 | 'Запълва всички елементи на масива от начален индекс до крайния индекс със статична стойност.', 139 | example: `arr.fill(2);
140 | console.log(arr);`, 141 | output: `[2, 2, 2]` 142 | }, 143 | { 144 | name: 'copyWithin', 145 | shortDesc: 'копирайте последователност от масивни елементи в масива.', 146 | desc: 147 | 'Копира последователност от масивни елементи в масива. Можете да посочите или само крайния елемент (откъдето започва да е по подразбиране до нула) или и началото, и края, разделени със запетая.', 148 | example: `arr.copyWithin(1);
149 | console.log(arr);`, 150 | output: `[5, 5, 1]` 151 | } 152 | ], 153 | iterate: [ 154 | { 155 | name: 'forEach', 156 | shortDesc: 'изпълнявайки функция, която ще създам за всеки елемент', 157 | desc: 158 | 'Методът forEach() изпълнява една предоставена функция веднъж за всеки елемент на масива.', 159 | example: `arr.forEach((element) => {
160 |   console.log(element)
161 | });`, 162 | output: `5
163 | 1
164 | 8` 165 | }, 166 | { 167 | name: 'map', 168 | shortDesc: 169 | 'създаване на нов масив от всеки елемент с функция, която създавам', 170 | desc: 171 | 'Създава нов масив с резултатите от извикването на дадена функция на всеки елемент в този масив.', 172 | example: `let map = arr.map(x => x + 1);
173 | console.log(map);`, 174 | output: `[6, 2, 9]` 175 | }, 176 | { 177 | name: 'entries', 178 | shortDesc: 'създаване на обект итератор', 179 | desc: 180 | 'Връща нов обект от Array Iterator, който съдържа двойките ключ/стойност за всеки индекс в масива. Има много приложения за итераторите, както и други методи, използвани с него, като values и keys', 181 | example: `let iterator = arr.entries();
182 | console.log(iterator.next().value);`, 183 | output: `[0, 5]
184 | // the 0 is the index,
185 | // the 5 is the first number` 186 | } 187 | ], 188 | find: { 189 | single: [ 190 | { 191 | name: 'includes', 192 | shortDesc: 'ако има определен елемент', 193 | desc: 194 | 'Определя дали даден масив съдържа определен елемент, връщайки се true или false, както е подходящо.', 195 | example: `console.log(arr.includes(1));`, 196 | output: `true` 197 | }, 198 | { 199 | name: 'indexOf', 200 | shortDesc: 'първият индекс на конкретен елемент', 201 | desc: 202 | 'Връща първия индекс, при който даден елемент може да бъде намерен в масива, или -1, ако то не присъства.', 203 | example: `console.log(arr.indexOf(5));`, 204 | output: `0` 205 | }, 206 | { 207 | name: 'lastIndexOf', 208 | shortDesc: 'последния индекс на конкретен елемент', 209 | desc: 210 | 'Връща последния (най-голям) индекс на елемент в масива, равен на зададената стойност, или -1, ако не е намерен.', 211 | example: `console.log(arr.lastIndexOf(5));`, 212 | output: `0` 213 | }, 214 | { 215 | name: 'find', 216 | shortDesc: 'първият елемент, който удовлетворява едно условие', 217 | desc: 218 | 'Връща намерената стойност в масива, ако елемент в масива удовлетворява предоставената функция за тестване или недефинирана, ако не е намерена. Подобно на findIndex(), но връща елемента вместо индекса.', 219 | example: `let isTiny = (el) => el < 2;
220 | console.log(arr.find(isTiny));`, 221 | output: `1` 222 | }, 223 | { 224 | name: 'findIndex', 225 | shortDesc: 226 | 'първият индекс на елемент, който отговаря на дадено условие', 227 | desc: 228 | 'Връща индекса на първия елемент в масива, който удовлетворява предоставената функция за тестване. В противен случай -1 се връща. Подобно на find(), но връща индекса вместо елемента.', 229 | example: `let isBig = (el) => el > 6;
230 | console.log(arr.findIndex(isBig));`, 231 | output: `2` 232 | }, 233 | { 234 | name: 'reduce', 235 | shortDesc: 236 | 'стойност чрез намаляване на масива, започни за да свършиш', 237 | desc: 238 | 'Прилагайте функция срещу акумулатор и всяка стойност на масива (от ляво на дясно), за да го намалите до единична стойност.', 239 | example: `let reducer = (a, b) => a + b;
240 | console.log(arr.reduce(reducer));`, 241 | output: `14` 242 | }, 243 | { 244 | name: 'reduceRight', 245 | shortDesc: 246 | 'стойност чрез намаляване на масива, завърши за да започнеш', 247 | desc: 248 | 'Прилагайте функция срещу акумулатор и всяка стойност на масива (от дясно на ляво), за да го намалите до единична стойност.', 249 | example: `[arr, [0, 1]].reduceRight((a, b) => {
250 |   return a.concat(b)
251 | }, [])`, 252 | output: `[0, 1, 5, 1, 8]` 253 | } 254 | ], 255 | many: [ 256 | { 257 | name: 'filter', 258 | shortDesc: 'стойности въз основа на състояние, което създавам', 259 | desc: 260 | 'Създава нов масив с всички елементи на този масив, за които предоставената филтрираща функция връща true.', 261 | example: `let filtered = arr.filter(el => el > 4);
262 | console.log(filtered)`, 263 | output: `[5, 8]` 264 | }, 265 | { 266 | name: 'every', 267 | shortDesc: 268 | 'независимо от това дали всеки елемент отговаря на дадено условие', 269 | desc: 270 | 'Връща true, ако всеки елемент в този масив удовлетворява предоставената функция за тестване.', 271 | example: `let isSmall = (el) => el < 10;
272 | console.log(arr.every(isSmall));`, 273 | output: `true` 274 | }, 275 | { 276 | name: 'some', 277 | shortDesc: 278 | 'независимо дали поне един елемент отговаря на дадено условие', 279 | desc: 280 | 'Връща true, ако поне един елемент в този масив отговаря на предоставената функция за тестване.', 281 | example: `let biggerThan4 = (el) => el > 4;
282 | console.log(arr.some(biggerThan4));`, 283 | output: `true` 284 | } 285 | ] 286 | } 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /src/store/cz.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: 'prvek nebo prvky z/do pole', 8 | desc: 'Přidá anebo odebere prvky z pole.', 9 | example: `arr.splice(2, 0, 'tacos');
10 | console.log(arr);`, 11 | output: `[5, 1, 'tacos', 8]` 12 | }, 13 | { 14 | name: 'push', 15 | shortDesc: 'prvky na konec pole', 16 | desc: 17 | 'Přidá jeden nebo více prvků na konec pole a vrátí novou délku pole.', 18 | example: `arr.push(2);
19 | console.log(arr);`, 20 | output: '[5, 1, 8, 2]' 21 | }, 22 | { 23 | name: 'unshift', 24 | shortDesc: 'prvky na začátek pole', 25 | desc: 26 | 'Přidá jeden nebo více prvků na začátek pole a vrátí novou délku pole.', 27 | example: `arr.unshift(2, 7);
28 | console.log(arr);`, 29 | output: '[2, 7, 5, 1, 8]' 30 | }, 31 | { 32 | name: 'concat', 33 | shortDesc: 'toto pole k jinému poli/polím anebo hodnotě/hodnotám', 34 | desc: 35 | 'Vrátí nové pole skládající z tohoto pole a jiných polí anebo hodnot.', 36 | example: `let arr2 = ['a', 'b', 'c'];
37 | let arr3 = arr.concat(arr2);
38 | console.log(arr3);`, 39 | output: `[5, 1, 8, 'a', 'b', 'c']` 40 | } 41 | ], 42 | removing: [ 43 | { 44 | name: 'splice', 45 | shortDesc: 'prvek nebo prvky z pole', 46 | desc: 'Přidá anebo odebere prvky z pole.', 47 | example: `arr.splice(2, 1);
48 | console.log(arr);`, 49 | output: `[5, 1]` 50 | }, 51 | { 52 | name: 'pop', 53 | shortDesc: 'poslední prvek pole', 54 | desc: 55 | 'Odebere poslední prvek z pole a vrátí odebraný prvek.', 56 | example: `arr.pop();
57 | console.log(arr);`, 58 | output: `[5, 1]` 59 | }, 60 | { 61 | name: 'shift', 62 | shortDesc: 'první prvek pole', 63 | desc: 64 | 'Odebere první prvek z pole a vrátí odebraný prvek.', 65 | example: `arr.shift();
66 | console.log(arr);`, 67 | output: `[1, 8]` 68 | }, 69 | { 70 | name: 'slice', 71 | shortDesc: 72 | 'jeden nebo více prvků pro práci beze změny pole', 73 | desc: 74 | 'slice() metoda vrací mělkou kopii části pole do nového pole. Lze specifikovat buď pouze počáteční prvek s tím, že konec se nastaví na délku pole, anebo konec i začátek oddělené čárkou. Původní pole zůstává beze změny.', 75 | example: `let slicedArr = arr.slice(1);
76 | console.log(arr);
77 | console.log(slicedArr);`, 78 | output: `[5, 1, 8]
79 | [1, 8]` 80 | } 81 | ], 82 | string: [ 83 | { 84 | name: 'join', 85 | shortDesc: 'spojit všechny prvky do jednoho řetezce', 86 | desc: `Spojí všechny prvky pole do jednoho řetezce. Lze je spojit dohromady nebo mezi ně něco vložit, elements.join(' - 87 | ') vrátí foo-bar`, 88 | example: `console.log(arr.join());`, 89 | output: `"5,1,8"` 90 | }, 91 | { 92 | name: 'toString', 93 | shortDesc: 'vrátit řetězec reprezentující pole', 94 | desc: 'Vrací řetězec reprezentující pole a jeho prvky.', 95 | example: `console.log(arr.toString());`, 96 | output: `"5,1,8"` 97 | }, 98 | { 99 | name: 'toLocaleString', 100 | shortDesc: 'vrátit lokalizovaný řetězec reprezentující pole', 101 | desc: 102 | 'Tato metoda je divná. Vrací lokalizovaný řetězec reprezentující pole a jeho prvky. To je často použitelné pro data a měny, ale má podivné vestavěné abstrakce, takže před použitím je vhodné se poradit s dokumentací.', 103 | example: `let date = [new Date()];
104 | const arrString = arr.toLocaleString();
105 | const dateString = date.toLocaleString();
106 | console.log(arrString, dateString);`, 107 | output: `"5,1,8 12/26/2017, 6:54:49 PM"` 108 | } 109 | ], 110 | ordering: [ 111 | { 112 | name: 'reverse', 113 | shortDesc: 'obrátit pořadí v poli', 114 | desc: 115 | 'Obrátí pořadí prvků pole - první bude poslední a poslední první.', 116 | example: `arr.reverse();
117 | console.log(arr);`, 118 | output: `[8, 1, 5]` 119 | }, 120 | { 121 | name: 'sort', 122 | shortDesc: 'seřadit prvky pole', 123 | desc: `Seřadí prvky pole a vrátí seřazené pole.
124 |
125 | Důležitá poznámka: Pokud není porovnávací funkce dodána, compareFunction, tak jsou prvky převedeny na řetězce a ty se porovnávají podle pořadí v Unicode. Např. "Malina" bude před "jahodou". U čísel, 9 je před 80, ale protože jsou čísla převedena na řetězce, tak "80" je před "9" podle Unicode pořadí. Dokumentace obsahuje další objasňující informace.`, 126 | example: `arr.sort();
127 | console.log(arr);`, 128 | output: `[1, 5, 8]` 129 | } 130 | ], 131 | other: [ 132 | { 133 | name: 'length', 134 | shortDesc: 'zjistit délku pole', 135 | desc: 'Vrátí počet prvků v poli.', 136 | example: `console.log(arr.length);`, 137 | output: `3` 138 | }, 139 | { 140 | name: 'fill', 141 | shortDesc: 'přiřadit všem prvkům pole statickou hodnotu', 142 | desc: 143 | 'Přiřadí všem prvkům pole statickou hodnotu.', 144 | example: `arr.fill(2);
145 | console.log(arr);`, 146 | output: `[2, 2, 2]` 147 | }, 148 | { 149 | name: 'copyWithin', 150 | shortDesc: 'zkopírovat řadu prvků v poli uvnitř pole', 151 | desc: 152 | 'Zkopíruje řadu prvků pole uvnitř pole. Lze specifikovat buď koncový prvek, kde počáteční pozice je nula, anebo počateční i koncový prvek, oddělené čárkou.', 153 | example: `arr.copyWithin(1);
154 | console.log(arr);`, 155 | output: `[5, 5, 1]` 156 | } 157 | ], 158 | iterate: [ 159 | { 160 | name: 'forEach', 161 | shortDesc: 'spuštění funkce nad každým prvkem', 162 | desc: 163 | 'forEach() metoda spustí předdefinovanou funkci jednou nad každým prvkem pole.', 164 | example: `arr.forEach((element) => {
165 |   console.log(element)
166 | });`, 167 | output: `5
168 | 1
169 | 8` 170 | }, 171 | { 172 | name: 'map', 173 | shortDesc: 174 | 'funkce, která vytvoří nové pole ze všech prvků', 175 | desc: 176 | 'Vytvoří nové pole, které je výsledkem volání definované funkce nad každým prvkem.', 177 | example: `let map = arr.map(x => x + 1);
178 | console.log(map);`, 179 | output: `[6, 2, 9]` 180 | }, 181 | { 182 | name: 'entries', 183 | shortDesc: 'iteračního objektu', 184 | desc: 185 | 'Vrátí nový iterátor pole, který obsahuje klíč-hodnota pár pro každou pozici v poli. Iterátor má mnoho případů užití jak samostatně, tak ve spojení s jinými metodami jako values nebo keys', 186 | example: `let iterator = arr.entries();
187 | console.log(iterator.next().value);`, 188 | output: `[0, 5]
189 | // the 0 is the index,
190 | // the 5 is the first number` 191 | } 192 | ], 193 | find: { 194 | single: [ 195 | { 196 | name: 'includes', 197 | shortDesc: 'prvek pokud existuje', 198 | desc: 199 | 'Zjistí jestli existuje daný prvek v poli a podle toho vrátí true nebo false.', 200 | example: `console.log(arr.includes(1));`, 201 | output: `true` 202 | }, 203 | { 204 | name: 'indexOf', 205 | shortDesc: 'první výskyt daného prvku', 206 | desc: 207 | 'Vrátí první výskyt daného prvku nebo -1 pokud prvek nenalezne.', 208 | example: `console.log(arr.indexOf(5));`, 209 | output: `0` 210 | }, 211 | { 212 | name: 'lastIndexOf', 213 | shortDesc: 'poslední výskyt daného prvku', 214 | desc: 215 | 'Vrátí poslední výskyt daného prvku nebo -1 pokud prvek nenalezne.', 216 | example: `console.log(arr.lastIndexOf(5));`, 217 | output: `0` 218 | }, 219 | { 220 | name: 'find', 221 | shortDesc: 'první prvek, který splňuje podmínku', 222 | desc: 223 | 'Vrátí nalezenou hodnotu v poli, pokud prvek v poli odpovídá definované testovací funkci nebo undefined pokud nenalezne. Podobné jako findIndex(), ale vrací prvek místo pozice.', 224 | example: `let isTiny = (el) => el < 2;
225 | console.log(arr.find(isTiny));`, 226 | output: `1` 227 | }, 228 | { 229 | name: 'findIndex', 230 | shortDesc: 'první výskyt prvku, který splňuje podmínku', 231 | desc: 232 | 'Vrátí pozici prvního prvku v poli, který splňuje definovanou testovací funkci. V ostatních případech vrací -1. Podobné jako find(), ale vrací pozici místo prvku.', 233 | example: `let isBig = (el) => el > 6;
234 | console.log(arr.findIndex(isBig));`, 235 | output: `2` 236 | }, 237 | { 238 | name: 'reduce', 239 | shortDesc: 'hodnotu po redukci pole z leva do prava', 240 | desc: 241 | 'Použije funkci na střadač (accumulator) a každou hodnotu pole (z leva do prava) redukuje do jedné hodnoty.', 242 | example: `let reducer = (a, b) => a + b;
243 | console.log(arr.reduce(reducer));`, 244 | output: `14` 245 | }, 246 | { 247 | name: 'reduceRight', 248 | shortDesc: 'hodnotu po redukci pole z prava do leva', 249 | desc: 250 | 'Použije funkci na střadač (accumulator) a každou hodnotu pole (z prava do leva) redukuje do jedné hodnoty.', 251 | example: `[arr, [0, 1]].reduceRight((a, b) => {
252 |   return a.concat(b)
253 | }, [])`, 254 | output: `[0, 1, 5, 1, 8]` 255 | } 256 | ], 257 | many: [ 258 | { 259 | name: 'filter', 260 | shortDesc: 'hodnoty, které splňují mnou vytvořenou podmínku', 261 | desc: 262 | 'Vytvoří nové pole se všemi prvky pole, pro které definovaná filtrovací funkce vrátí hodnotu true.', 263 | example: `let filtered = arr.filter(el => el > 4);
264 | console.log(filtered)`, 265 | output: `[5, 8]` 266 | }, 267 | { 268 | name: 'every', 269 | shortDesc: 'jestli všechny prvky splňují podmínku', 270 | desc: 271 | 'Vrací true pokud každý prvek odpovídá definované testovací funkci.', 272 | example: `let isSmall = (el) => el < 10;
273 | console.log(arr.every(isSmall));`, 274 | output: `true` 275 | }, 276 | { 277 | name: 'some', 278 | shortDesc: 'jestli alespoň jeden prvek splňuje podmínku', 279 | desc: 280 | 'Vrací true pokud alespoň jeden prvek odpovídá definované testovací funkci.', 281 | example: `let biggerThan4 = (el) => el > 4;
282 | console.log(arr.some(biggerThan4));`, 283 | output: `true` 284 | } 285 | ] 286 | } 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /src/store/de.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: 'Elemente in einen Array einfügen', 8 | desc: 'Fügt Elemente zu einem Array hinzu oder entfernt welche.', 9 | example: `arr.splice(2, 0, 'tacos');
10 | console.log(arr);`, 11 | output: `[5, 1, 'tacos', 8]` 12 | }, 13 | { 14 | name: 'push', 15 | shortDesc: 'Elemente an das Ende eines Arrays anhängen', 16 | desc: 17 | 'Hängt ein oder mehrere Elemente an einen Array an und gibt die neue Länge des Arrays zurück.', 18 | example: `arr.push(2);
19 | console.log(arr);`, 20 | output: '[5, 1, 8, 2]' 21 | }, 22 | { 23 | name: 'unshift', 24 | shortDesc: 'Elemente an den Anfang eines Arrays hinzufügen', 25 | desc: 26 | 'Fügt ein oder mehrere Elemente an den Anfang eines Arrays an und gibt die neue Länge des Arrays zurück.', 27 | example: `arr.unshift(2, 7);
28 | console.log(arr);`, 29 | output: '[2, 7, 5, 1, 8]' 30 | }, 31 | { 32 | name: 'concat', 33 | shortDesc: 'diesen Array zu anderen Arrays und/oder Werten hinzufügen', 34 | desc: 35 | 'Gibt einen neuen Array bestehend aus diesem Array zusammen mit anderen Array(s) und/oder Werten zurück.', 36 | example: `let arr2 = ['a', 'b', 'c'];
37 | let arr3 = arr.concat(arr2);
38 | console.log(arr3);`, 39 | output: `[5, 1, 8, 'a', 'b', 'c']` 40 | } 41 | ], 42 | removing: [ 43 | { 44 | name: 'splice', 45 | shortDesc: 'Elemente aus einem Array entfernen', 46 | desc: 'Fügt Elemente einem Array hinzu und/oder entfernt welche.', 47 | example: `arr.splice(2, 1);
48 | console.log(arr);`, 49 | output: `[5, 1]` 50 | }, 51 | { 52 | name: 'pop', 53 | shortDesc: 'das letzte Element eines Arrays entfernen', 54 | desc: 'Entfernt das letzte Element eines Arrays und gibt es zurück.', 55 | example: `arr.pop();
56 | console.log(arr);`, 57 | output: `[5, 1]` 58 | }, 59 | { 60 | name: 'shift', 61 | shortDesc: 'das erste Element eines Arrays entfernen', 62 | desc: 'Entfernt das erste Element eines Arrays und gibt es zurück.', 63 | example: `arr.shift();
64 | console.log(arr);`, 65 | output: `[1, 8]` 66 | }, 67 | { 68 | name: 'slice', 69 | // fehlt noch 70 | shortDesc: 71 | 'mindestens ein Element, ohne den eigentlichen Array zu verändern, entfernen', 72 | desc: 73 | 'Die slice()-Methode schreibt eine flache Kopie eines Teils des Arrays in ein neues Array-Objekt. Man kann entweder nur den Index für das letzte Elemente (dann wird der Index für das erste Element auf 0 gesetzt) oder sowohl den Index für das erste und das letzte Element kommagetrennt angeben. Der Original-Array wird nicht verändert.', 74 | example: `let slicedArr = arr.slice(1);
75 | console.log(arr);
76 | console.log(slicedArr);`, 77 | output: `[5, 1, 8]
78 | [1, 8]` 79 | } 80 | ], 81 | string: [ 82 | { 83 | name: 'join', 84 | shortDesc: 'alle Elemente eines Arrays in einen String zusammenführen.', 85 | desc: `Führt alle Elemente eines Arrays in einem String zusammen. Man kann die Elemente entweder mit oder ohne Trennzeichen zusammenführen. elements.join(' - 86 | ') gibt foo-bar`, 87 | example: `console.log(arr.join());`, 88 | output: `"5,1,8"` 89 | }, 90 | { 91 | name: 'toString', 92 | shortDesc: 'einen String, der den Array repräsentiert, zurückgegeben.', 93 | desc: 94 | 'Gibt einen String, der den Array und alle darin enthaltenen Elemente beinhaltet, zurück.', 95 | example: `console.log(arr.toString());`, 96 | output: `"5,1,8"` 97 | }, 98 | { 99 | name: 'toLocaleString', 100 | shortDesc: 101 | 'einen an die Sprache angepassten String, der den Array repräsentiert, zurückgeben.', 102 | desc: 103 | 'Diese Methode ist ein bisschen komisch. Sie gibt einen an die Sprache angepassten String, der den Array und alle seine Elemente beinhaltet, zurück. Dies ist sehr nützlich für Datumsangaben und Währungen, hat aber einige seltsame Verhaltensweisen, so dass du am besten die genaue Dokumentation durchlesen solltest.', 104 | example: `let date = [new Date()];
105 | const arrString = arr.toLocaleString();
106 | const dateString = date.toLocaleString();
107 | console.log(arrString, dateString);`, 108 | output: `"5,1,8 12/26/2017, 6:54:49 PM"` 109 | } 110 | ], 111 | ordering: [ 112 | { 113 | name: 'reverse', 114 | shortDesc: 'die Reihenfolge eines Arrays umkehren', 115 | desc: 116 | 'Kehrt die Reihenfolge der Elemente in einem Array um, das erste wird zum letzten Element, das letzte zum ersten.', 117 | example: `arr.reverse();
118 | console.log(arr);`, 119 | output: `[8, 1, 5]` 120 | }, 121 | { 122 | name: 'sort', 123 | shortDesc: 'die Elemente in einem Array sortieren', 124 | desc: 125 | 'Sortiert die Elemente eines Arrays in aufsteigender Reihenfolge.', 126 | example: `arr.sort();
127 | console.log(arr);`, 128 | output: `[1, 5, 8]` 129 | } 130 | ], 131 | other: [ 132 | { 133 | name: 'length', 134 | shortDesc: 'die Länge des Arrays herausfinden', 135 | desc: 'Gibt die Zahl aller Elemente in einem Array zurück.', 136 | example: `console.log(arr.length);`, 137 | output: `3` 138 | }, 139 | { 140 | name: 'fill', 141 | shortDesc: 142 | 'allen Elementen des Arrays einen bestimmten Wert zuweisen', 143 | desc: 144 | 'Weist alle Elementen in einem Array vom Start- bis zum Endindex einen bestimmten Wert zu.', 145 | example: `arr.fill(2);
146 | console.log(arr);`, 147 | output: `[2, 2, 2]` 148 | }, 149 | { 150 | name: 'copyWithin', 151 | shortDesc: 152 | 'einen Folge von Elementen des Arrays innerhalb des Arrays kopieren', 153 | desc: 154 | 'Kopiert eine Reihe von Elementen des Arrays innerhalb des Arrays. Du kannst entweder nur das letzte Element (dann wird der Startindex auf 0 gesetzt) oder sowohl das erste als auch das letzte kommagetrennt festlegen.', 155 | example: `arr.copyWithin(1);
156 | console.log(arr);`, 157 | output: `[5, 5, 1]` 158 | } 159 | ], 160 | iterate: [ 161 | { 162 | name: 'forEach', 163 | shortDesc: 164 | 'eine selbstdefinierte Funktion auf jedes Elemente des Arrays anwenden', 165 | desc: 166 | 'Die forEach()-Methode wendet eine gegebene Funktion auf jedes Element im Array an.', 167 | example: `arr.forEach((element) => {
168 |   console.log(element)
169 | });`, 170 | output: `5
171 | 1
172 | 8` 173 | }, 174 | { 175 | name: 'map', 176 | shortDesc: 177 | 'einen neuen Array basierend auf einer auf alle Elemente angewendeten Funktion erstellen', 178 | desc: 179 | 'Erstellt einen neuen Array, dessen Elemente auf dem gegebenem Array, auf die eine gegebene Funktion angewendet wurde, basieren.', 180 | example: `let map = arr.map(x => x + 1);
181 | console.log(map);`, 182 | output: `[6, 2, 9]` 183 | }, 184 | { 185 | name: 'entries', 186 | shortDesc: 'ein Iterator-Objekt erstellen', 187 | desc: 188 | 'Gibt ein Iterator-Objekt zurück, das zu jedem Index den Wert des Elements beinhaltet. Es gibt eine Vielzahl an Anwendungen für Iteratoren und andere Methoden, die in Verbindung mit Iteratoren genutzt werden, wie key oder value.', 189 | example: `let iterator = arr.entries();
190 | console.log(iterator.next().value);`, 191 | output: `[0, 5]
192 | // the 0 is the index,
193 | // the 5 is the first number` 194 | } 195 | ], 196 | find: { 197 | single: [ 198 | { 199 | name: 'includes', 200 | shortDesc: 'herausfinden, ob ein bestimmtes Element im Array vorkommt', 201 | desc: 202 | 'Existiert ein bestimmtes Element im Array, wird true, ansonsten false, zurückgegeben.', 203 | example: `console.log(arr.includes(1));`, 204 | output: `true` 205 | }, 206 | { 207 | name: 'indexOf', 208 | shortDesc: 'herausfinden, was der erste Index eines Elements ist', 209 | desc: 210 | 'Gibt den ersten Index, an dem das Element gefunden werden kann, zurück, oder -1, falls es nicht vorkommt.', 211 | example: `console.log(arr.indexOf(5));`, 212 | output: `0` 213 | }, 214 | { 215 | name: 'lastIndexOf', 216 | shortDesc: 'den letzten Index eines Elements finden', 217 | desc: 218 | 'Gibt den letzten (größten) Index zurück, an dem ein Element gefunden werden kann, oder -1, falls es nicht im Array vorkommt.', 219 | example: `console.log(arr.lastIndexOf(5));`, 220 | output: `0` 221 | }, 222 | { 223 | name: 'find', 224 | shortDesc: 'das erste Element, das eine Bedingung erfüllt, finden', 225 | desc: 226 | 'Gibt das erste gefundene Element aus dem Array zurück, das die gegebene Bedingung erfüllt, wenn mindestens ein Element die gegebene Bedingung erfüllt, sonst wird undefined zurückgegeben. Ähnlich zu findIndex(), aber find() gibt das Element und nicht den Index zurück.', 227 | example: `let isTiny = (el) => el < 2;
228 | console.log(arr.find(isTiny));`, 229 | output: `1` 230 | }, 231 | { 232 | name: 'findIndex', 233 | shortDesc: 234 | 'den ersten Index eines Elements, das eine Bedingung erfüllt, finden', 235 | desc: 236 | 'Gibt den Index des ersten Elements im Array, das die gegebene Bedingung erfüllt, zurück. Erfüllt kein Element die Bedingung, wird -1 zurückgegeben. Ähnlich zu find(), aber findIndex() gibt den Index statt des Elements zurück.', 237 | example: `let isBig = (el) => el > 6;
238 | console.log(arr.findIndex(isBig));`, 239 | output: `2` 240 | }, 241 | { 242 | name: 'reduce', 243 | shortDesc: 244 | 'den Array auf einen einzigen Wert reduzieren, von links nach rechts', 245 | desc: 246 | 'Reduziert das Array auf einen einzigen Wert, indem es jeweils zwei Elemente (von links nach rechts) durch eine angegebene Funktion reduziert.', 247 | example: `let reducer = (a, b) => a + b;
248 | console.log(arr.reduce(reducer));`, 249 | output: `14` 250 | }, 251 | { 252 | name: 'reduceRight', 253 | shortDesc: 254 | 'den Array auf einen einzigen Wert reduzieren, von rechts nach links', 255 | desc: 256 | 'Wendet eine Funktion gegen einen Akkumulator auf jeden Wert des Arrays (von rechts nach links) an und reduziert es um einen einzelnen Wert.', 257 | example: `[arr, [0, 1]].reduceRight((a, b) => {
258 |   return a.concat(b)
259 | }, [])`, 260 | output: `[0, 1, 5, 1, 8]` 261 | } 262 | ], 263 | many: [ 264 | { 265 | name: 'filter', 266 | shortDesc: 267 | 'Werte basierend auf einer selbsterstellten Bedingung finden', 268 | desc: 269 | 'Erstellt einen neuen Array mit allen Elementen des Strings, die eine gegebene Bedingung erfüllen.', 270 | example: `let filtered = arr.filter(el => el > 4);
271 | console.log(filtered)`, 272 | output: `[5, 8]` 273 | }, 274 | { 275 | name: 'every', 276 | shortDesc: 277 | 'herausfinden, ob alle Elemente des Arrays eine Bedingung erfüllen', 278 | desc: 279 | 'Gibt true zurück, wenn alle Elemente des Arrays eine gegebene Bedingung erfüllen.', 280 | example: `let isSmall = (el) => el < 10;
281 | console.log(arr.every(isSmall));`, 282 | output: `true` 283 | }, 284 | { 285 | name: 'some', 286 | shortDesc: 287 | 'herausfinden, ob mindestens ein Element im Array eine Bedingung erfüllt', 288 | desc: 289 | 'Gibt true zurück, wenn zumindest ein Element des Arrays eine gegebene Bedingung erfüllt.', 290 | example: `let biggerThan4 = (el) => el > 4;
291 | console.log(arr.some(biggerThan4));`, 292 | output: `true` 293 | } 294 | ] 295 | } 296 | } 297 | } 298 | -------------------------------------------------------------------------------- /src/store/el.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: 'στοιχείο/α σε έναν πίνακα', 8 | desc: 'Προσθέτει ή αφαιρεί στοιχεία σε έναν πίνακα.', 9 | example: `arr.splice(2, 0, 'tacos');
10 | console.log(arr);`, 11 | output: `[5, 1, 'tacos', 8]` 12 | }, 13 | { 14 | name: 'push', 15 | shortDesc: 'στοιχεία στο τέλος του πίνακα', 16 | desc: 17 | 'Προσθέτει ένα ή περισσότερα στοιχεία στο τέλος του πίνακα και επιστρέφει το νέο μήκος του.', 18 | example: `arr.push(2);
19 | console.log(arr);`, 20 | output: '[5, 1, 8, 2]' 21 | }, 22 | { 23 | name: 'unshift', 24 | shortDesc: 'στοιχεία στην αρχή του πίνακα', 25 | desc: 26 | 'Προσθέτει ένα ή περισσότερα στοιχεία στην αρχή του πίνακα και επιστρέφει το νέο μήκος του.', 27 | example: `arr.unshift(2, 7);
28 | console.log(arr);`, 29 | output: '[2, 7, 5, 1, 8]' 30 | }, 31 | { 32 | name: 'concat', 33 | shortDesc: 'αυτόν τον πίνακα σε άλλον(ους) πίνακα(ες) ή/και τιμή(ες)', 34 | desc: 35 | 'Επιστρέφει έναν νέο πίνακα που αποτελείται από τον τρέχοντα και άλλον(ους) πίνακα(ες) ή/και τιμή(ες).', 36 | example: `let arr2 = ['a', 'b', 'c'];
37 | let arr3 = arr.concat(arr2);
38 | console.log(arr3);`, 39 | output: `[5, 1, 8, 'a', 'b', 'c']` 40 | } 41 | ], 42 | removing: [ 43 | { 44 | name: 'splice', 45 | shortDesc: 'στοιχείο/α απο τον πίνακα', 46 | desc: 'Προσθέτει ή αφερεί στοιχεία απο τον πίνακα.', 47 | example: `arr.splice(2, 1);
48 | console.log(arr);`, 49 | output: `[5, 1]` 50 | }, 51 | { 52 | name: 'pop', 53 | shortDesc: 'το τελευταίο στοιχείο του πίνακα', 54 | desc: 55 | 'Αφαιρεί και επιστρέφει το τελευταίο στοιχείο του πίνακα.', 56 | example: `arr.pop();
57 | console.log(arr);`, 58 | output: `[5, 1]` 59 | }, 60 | { 61 | name: 'shift', 62 | shortDesc: 'το πρώτο στοιχείο του πίνακα', 63 | desc: 64 | 'Αφαιρεί και επιστρέφει το πρώτο στοιχείο του πίνακα.', 65 | example: `arr.shift();
66 | console.log(arr);`, 67 | output: `[1, 8]` 68 | }, 69 | { 70 | name: 'slice', 71 | shortDesc: 72 | 'ένα ή παραπάνω στοιχεία, αφήνοντας τον αρχικό πίνακα αμετάβλητο', 73 | desc: 74 | 'Η μεθοδος slice() επιστέφει ένα "ρηχό" αντίγραφο τμήματος του αρχικού πίνακα, σαν έναν νέο. Μπορείτε να θέσετε την αρχή μόνο (οπότε το τέλος θα είναι το μήκος του πίνακα), είτε την αρχή και το τέλος, χωρισμένα με κόμμα.', 75 | example: `let slicedArr = arr.slice(1);
76 | console.log(arr);
77 | console.log(slicedArr);`, 78 | output: `[5, 1, 8]
79 | [1, 8]` 80 | } 81 | ], 82 | string: [ 83 | { 84 | name: 'join', 85 | shortDesc: 'ενώσω όλα τα στοιχεία του πίνακα σε ένα αλφαριθμητικό', 86 | desc: `Ενώνει όλα τα στοιχεία του πίνακα σε ένα αλφαριθμητικό. Μπορείτε να θέσετε και κάποιο συνδετικό ανάμεσα, elements.join(' - 87 | ') επιστρέφει foo-bar`, 88 | example: `console.log(arr.join());`, 89 | output: `"5,1,8"` 90 | }, 91 | { 92 | name: 'toString', 93 | shortDesc: 'επιστρέψω τον πίνακα σαν ένα αλφαριθμητικό.', 94 | desc: 'Επιστρέφει τον πίνακα και τα στοιχεία του σαν ένα αλφαριθμητικό.', 95 | example: `console.log(arr.toString());`, 96 | output: `"5,1,8"` 97 | }, 98 | { 99 | name: 'toLocaleString', 100 | shortDesc: 'επιστρέψω τον πίνακα σαν ένα μεταφρασμένο αλφαριθμητικό.', 101 | desc: 102 | 'Επιστρέφει ένα μεταφρασμένο αλφαρηθμητικό που αναπαριστά τον πίνακα και τις τιμές του. Αυτή η μέθοδος είναι χρήσιμη για ημερομηνίες και νομίσματα, αλλά επειδή η υλοποίησή της ποικίλει, καλύτερα να συμβουλεύεστε τα κείμενα όταν την χρησιμοποιείται.', 103 | example: `let date = [new Date()];
104 | const arrString = arr.toLocaleString();
105 | const dateString = date.toLocaleString();
106 | console.log(arrString, dateString);`, 107 | output: `"5,1,8 12/26/2017, 6:54:49 PM"` 108 | } 109 | ], 110 | ordering: [ 111 | { 112 | name: 'reverse', 113 | shortDesc: 'αντιστρέψω τον πίνακα', 114 | desc: 115 | 'Αντιστέφει την σειρά των στοιχέιων του πίνακα — το πρώτο γίνεται τελευταίο και αντίστροφα.', 116 | example: `arr.reverse();
117 | console.log(arr);`, 118 | output: `[8, 1, 5]` 119 | }, 120 | { 121 | name: 'sort', 122 | shortDesc: 'ταξινομεί τα στοιχέια του πίνακα', 123 | desc: `Ταξινομεί τα στοιχεία μέσα στον πίνακα και τον επιστρέφει.
124 |
125 | Σημαντική Σημείωση: Αν δεν παρέχετε την μέθοδο compareFunction, τα στοιχεία μετατρέπονται σε Unicode αλφαριθμητικά και ταξινομούνται. Για παράδειγμα, το "Banana" θα προηγείται του "cherry". Σε αριθμητική σειρά, το 9 προηγείται του 80, αλλά επειδή τα νούμερα μετατρέπονται σε αλφαριθμητικά, το "80" θα προηγείται του "9" σε σειρά Unicode. Ανατρέξτε στα κείμενα για περισσότερες διευκρινύσεις.`, 126 | example: `arr.sort();
127 | console.log(arr);`, 128 | output: `[1, 5, 8]` 129 | } 130 | ], 131 | other: [ 132 | { 133 | name: 'length', 134 | shortDesc: 'επιστρέψω το μέγεθος του πίνακα', 135 | desc: 'Επιτρέφει το πλήθος των στοιχείων του πίνακα.', 136 | example: `console.log(arr.length);`, 137 | output: `3` 138 | }, 139 | { 140 | name: 'fill', 141 | shortDesc: 'αναθέσω μια στατική τιμή σε όλα τα στοιχεία του πίνακα', 142 | desc: 143 | 'Γεμίζει όλα τα στοιχεία του πίνακα, απο μία αρχική θέση έως μία τελική θέση, αναθέτοντας μία συγκεκριμένη στατική τιμή.', 144 | example: `arr.fill(2);
145 | console.log(arr);`, 146 | output: `[2, 2, 2]` 147 | }, 148 | { 149 | name: 'copyWithin', 150 | shortDesc: 'αντιγράψω μέρος του πίνακα σε άλλη θέση.', 151 | desc: 152 | 'Αντιγράφει μέρος του πίνακα σε άλλη θέση, χωρίς να μεταβάλει το μέγεθός του. Μπορείτε να θέσετε είτε την τελική θέση στον πίνακα (οπότε αρχική ειναι η μηδενική), είτε την αρχική και την τελική χωρισμένες με κόμμα.', 153 | example: `arr.copyWithin(1);
154 | console.log(arr);`, 155 | output: `[5, 5, 1]` 156 | } 157 | ], 158 | iterate: [ 159 | { 160 | name: 'forEach', 161 | shortDesc: 'εκτελέσω μια μέθοδο για κάθε στοιχείο του πίνακα', 162 | desc: 163 | 'Η μέθοδος forEach(), εκτελεί την μέθοδο που παρέχετε, μια φορά για κάθε στοιχείο στον πίνακα.', 164 | example: `arr.forEach((element) => {
165 |   console.log(element)
166 | });`, 167 | output: `5
168 | 1
169 | 8` 170 | }, 171 | { 172 | name: 'map', 173 | shortDesc: 174 | 'δημιουργήσω ένα νέο πίνακα, για κάθε στοιχείο του πίνακα, εφαρμόζοντας την συνάρτηση που θέλω', 175 | desc: 176 | 'Εφαρμόζοντας την δοθείσα συνάρτηση σε κάθε στοιχείο του πίνακα, δημιουργείται ένας νέος.', 177 | example: `let map = arr.map(x => x + 1);
178 | console.log(map);`, 179 | output: `[6, 2, 9]` 180 | }, 181 | { 182 | name: 'entries', 183 | shortDesc: 'δημιουργήσω ένα iterator αντικείμενο (επανάληψης)', 184 | desc: 185 | 'Επιστρέφει ένα αντικείμενο iterator (επανάληψης), το οποίο επιστρέφει τα ζεύγη κλειδιού/τιμής για κάθε θέση του πίνακα. Οι iterators έχουν πολλές χρήσεις, όπως και άλλες μεθόδοι που μπορούν να χρησιμοποιηθούν μαζί, όπως τα values και τα keys', 186 | example: `let iterator = arr.entries();
187 | console.log(iterator.next().value);`, 188 | output: `[0, 5]
189 | // the 0 is the index,
190 | // the 5 is the first number` 191 | } 192 | ], 193 | find: { 194 | single: [ 195 | { 196 | name: 'includes', 197 | shortDesc: 'αν περιέχει ένα συγκεκριμένο στοιχείο', 198 | desc: 199 | 'Επιστρέφει αληθής (true) ή ψευδής (false), αν ο πίνακας περιέχει την συγκεκριμένη τιμή.', 200 | example: `console.log(arr.includes(1));`, 201 | output: `true` 202 | }, 203 | { 204 | name: 'indexOf', 205 | shortDesc: 'την πρώτη θέση στην οποία υπάρχει ένα συγκεκριμένο στοιχείο', 206 | desc: 207 | 'Επιστρέφει την πρώτη θέση στην οποία βρίσκεται ένα συγκριμένο στοιχείο. Αν το στοιχείο δεν βρίσκεται στον πίνακα, τότε επιστρέφει -1.', 208 | example: `console.log(arr.indexOf(5));`, 209 | output: `0` 210 | }, 211 | { 212 | name: 'lastIndexOf', 213 | shortDesc: 'την τελευταία θέση στην οποία υπάρχει ένα συγκεκριμένο στοιχείο', 214 | desc: 215 | 'Επιστρέφει την τελευταία θέση στην οποία βρίσκεται ένα συγκριμένο στοιχείο. Αν το στοιχείο δεν βρίσκεται στον πίνακα, τότε επιστρέφει -1.', 216 | example: `console.log(arr.lastIndexOf(5));`, 217 | output: `0` 218 | }, 219 | { 220 | name: 'find', 221 | shortDesc: 'το πρώτο στοιχείο που ικανοποιεί μια συνθήκη', 222 | desc: 223 | 'Επιστρέφει την τιμή που βρίσκει στον πίνακα, εφόσον ικανοποιεί την συνάρτηση που έχετε δώσει. Διαφορετικά, επιστρέφει undefined. Παρόμοια με το findIndex(), απλά επιστρέφει την τιμή αντί για την θέση.', 224 | example: `let isTiny = (el) => el < 2;
225 | console.log(arr.find(isTiny));`, 226 | output: `1` 227 | }, 228 | { 229 | name: 'findIndex', 230 | shortDesc: 'την πρώτη θέση στην οποία η τιμή του στοιχείου ικανοποιεί την συνθήκη', 231 | desc: 232 | 'Επιστρέφει την θέση του πρώτου στοιχείου στον πίνακα, το οποίο ικανοποιεί την δοθείσα συνάρτηση. Διαφορετικά, επιστρέφει -1. Παρόμοια με την find(), αλλά επιστρέφει την θέση αντί για την τιμή.', 233 | example: `let isBig = (el) => el > 6;
234 | console.log(arr.findIndex(isBig));`, 235 | output: `2` 236 | }, 237 | { 238 | name: 'reduce', 239 | shortDesc: 'μια τιμή συρρικνώνοντας τα στοιχεία του πίνακα, απο την αρχή ως το τέλος', 240 | desc: 241 | 'Εφαρμόζει μια συνάρτηση πάνω σε ένα συσσωρευτή (accumulator) και σε κάθε τιμή του πίνακα (από τα αριστερά προς τα δεξιά) μέχρι να μείνει μόνο μια τιμή.', 242 | example: `let reducer = (a, b) => a + b;
243 | console.log(arr.reduce(reducer));`, 244 | output: `14` 245 | }, 246 | { 247 | name: 'reduceRight', 248 | shortDesc: 'μια τιμή συρρικνώνοντας τα στοιχεία του πίνακα, απο το τέλος ως την αρχή', 249 | desc: 250 | 'Εφαρμόζει μια συνάρτηση πάνω σε ένα συσσωρευτή (accumulator) και σε κάθε τιμή του πίνακα (από τα δεξιά προς τα αριστερά) μέχρι να μείνει μόνο μια τιμή.', 251 | example: `[arr, [0, 1]].reduceRight((a, b) => {
252 |   return a.concat(b)
253 | }, [])`, 254 | output: `[0, 1, 5, 1, 8]` 255 | } 256 | ], 257 | many: [ 258 | { 259 | name: 'filter', 260 | shortDesc: 'τιμές με βάση μια συνθήκη που θέτω', 261 | desc: 262 | 'Φτιάχνει έναν καινούριο πίνακα, από τα στοιχεία του πίνακα τα οποία ικανονοποιούν την δοθείσα συνάρτηση φιλτραρίσματος.', 263 | example: `let filtered = arr.filter(el => el > 4);
264 | console.log(filtered)`, 265 | output: `[5, 8]` 266 | }, 267 | { 268 | name: 'every', 269 | shortDesc: 'εάν κάθε στοιχείο ικανοποιεί μια συνθήκη', 270 | desc: 271 | 'Επιστρέφει αληθής (true) εάν κάθε στοιχείο στον πίνακα ικανοποιεί την δοθείσα συνάρτηση.', 272 | example: `let isSmall = (el) => el < 10;
273 | console.log(arr.every(isSmall));`, 274 | output: `true` 275 | }, 276 | { 277 | name: 'some', 278 | shortDesc: 'εάν τουλάχιστον ένα στοιχείο ικανοποιεί μια συνθήκη', 279 | desc: 280 | 'Επιστρέφει αληθής (true) εάν τουλάχιστον ένα στοιχείο στον πίνακα ικανοποιεί την δοθείσα συνάρτηση.', 281 | example: `let biggerThan4 = (el) => el > 4;
282 | console.log(arr.some(biggerThan4));`, 283 | output: `true` 284 | } 285 | ] 286 | } 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /src/store/en.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: 'element/s to an array', 8 | desc: 'Adds and/or removes elements from an array.', 9 | example: `arr.splice(2, 0, 'tacos');
10 | console.log(arr);`, 11 | output: `[5, 1, 'tacos', 8]` 12 | }, 13 | { 14 | name: 'push', 15 | shortDesc: 'elements to the end of an array', 16 | desc: 17 | 'Adds one or more elements to the end of an array and returns the new length of the array.', 18 | example: `arr.push(2);
19 | console.log(arr);`, 20 | output: '[5, 1, 8, 2]' 21 | }, 22 | { 23 | name: 'unshift', 24 | shortDesc: 'elements to the front of an array', 25 | desc: 26 | 'Adds one or more elements to the front of an array and returns the new length of the array.', 27 | example: `arr.unshift(2, 7);
28 | console.log(arr);`, 29 | output: '[2, 7, 5, 1, 8]' 30 | }, 31 | { 32 | name: 'concat', 33 | shortDesc: 'this array to other array(s) and/or value(s)', 34 | desc: 35 | 'Returns a new array comprised of this array joined with other array(s) and/or value(s).', 36 | example: `let arr2 = ['a', 'b', 'c'];
37 | let arr3 = arr.concat(arr2);
38 | console.log(arr3);`, 39 | output: `[5, 1, 8, 'a', 'b', 'c']` 40 | } 41 | ], 42 | removing: [ 43 | { 44 | name: 'splice', 45 | shortDesc: 'element/s from an array', 46 | desc: 'Adds and/or removes elements from an array.', 47 | example: `arr.splice(2, 1);
48 | console.log(arr);`, 49 | output: `[5, 1]` 50 | }, 51 | { 52 | name: 'pop', 53 | shortDesc: 'the last element of the array', 54 | desc: 55 | 'Removes the last element from an array and returns that element.', 56 | example: `arr.pop();
57 | console.log(arr);`, 58 | output: `[5, 1]` 59 | }, 60 | { 61 | name: 'shift', 62 | shortDesc: 'the first element of the array', 63 | desc: 64 | 'Removes the first element from an array and returns that element.', 65 | example: `arr.shift();
66 | console.log(arr);`, 67 | output: `[1, 8]` 68 | }, 69 | { 70 | name: 'slice', 71 | shortDesc: 72 | 'one or more elements in order for use, leaving the array as is', 73 | desc: 74 | 'The slice() method returns a shallow copy of a portion of an array into a new array object. You can specify either just the beginning element (where end will default to the arrays length) or both the beginning and the end, comma-separated. The original array will not be modified.', 75 | example: `let slicedArr = arr.slice(1);
76 | console.log(arr);
77 | console.log(slicedArr);`, 78 | output: `[5, 1, 8]
79 | [1, 8]` 80 | } 81 | ], 82 | string: [ 83 | { 84 | name: 'join', 85 | shortDesc: 'join all elements of the array into a string', 86 | desc: `Joins all elements of an array into a string. You can join it together as is or with something in between, elements.join(' - 87 | ') gives you foo-bar`, 88 | example: `console.log(arr.join());`, 89 | output: `"5,1,8"` 90 | }, 91 | { 92 | name: 'toString', 93 | shortDesc: 'return a string representing the array.', 94 | desc: 'Returns a string representing the array and its elements.', 95 | example: `console.log(arr.toString());`, 96 | output: `"5,1,8"` 97 | }, 98 | { 99 | name: 'toLocaleString', 100 | shortDesc: 'return a localized string representing the array.', 101 | desc: 102 | 'This one is a bit wacko. Returns a localized string representing the array and its elements. This is very useful for dates and currency and has some strange native abstractions, so best to consult the docs when using it', 103 | example: `let date = [new Date()];
104 | const arrString = arr.toLocaleString();
105 | const dateString = date.toLocaleString();
106 | console.log(arrString, dateString);`, 107 | output: `"5,1,8 12/26/2017, 6:54:49 PM"` 108 | } 109 | ], 110 | ordering: [ 111 | { 112 | name: 'reverse', 113 | shortDesc: 'reverse the order of the array', 114 | desc: 115 | 'Reverses the order of the elements of an array in place — the first becomes the last, and the last becomes the first.', 116 | example: `arr.reverse();
117 | console.log(arr);`, 118 | output: `[8, 1, 5]` 119 | }, 120 | { 121 | name: 'sort', 122 | shortDesc: 'sort the items of the array', 123 | desc: `Sorts the elements of an array in place and returns the array.
124 |
125 | Important note: If compareFunction is not supplied, elements are sorted by converting them to strings and comparing strings in Unicode code point order. For example, "Banana" comes before "cherry". In a numeric sort, 9 comes before 80, but because numbers are converted to strings, "80" comes before "9" in Unicode order. The docs have more information to clarify.`, 126 | example: `arr.sort();
127 | console.log(arr);`, 128 | output: `[1, 5, 8]` 129 | } 130 | ], 131 | other: [ 132 | { 133 | name: 'length', 134 | shortDesc: 'find the length of the array', 135 | desc: 'Returns the number of elements in that array.', 136 | example: `console.log(arr.length);`, 137 | output: `3` 138 | }, 139 | { 140 | name: 'fill', 141 | shortDesc: 'fill all the elements of the array with a static value', 142 | desc: 143 | 'Fills all the elements of an array from a start index to an end index with a static value.', 144 | example: `arr.fill(2);
145 | console.log(arr);`, 146 | output: `[2, 2, 2]` 147 | }, 148 | { 149 | name: 'copyWithin', 150 | shortDesc: 'copy a sequence of array elements within the array.', 151 | desc: 152 | 'Copies a sequence of array elements within the array. You can specify either just the ending element (where begin will default to zero) or both the beginning and the end, comma-separated.', 153 | example: `arr.copyWithin(1);
154 | console.log(arr);`, 155 | output: `[5, 5, 1]` 156 | } 157 | ], 158 | iterate: [ 159 | { 160 | name: 'forEach', 161 | shortDesc: 'executing a function I will create for each element', 162 | desc: 163 | 'The forEach() method executes a provided function once for each array element.', 164 | example: `arr.forEach((element) => {
165 |   console.log(element)
166 | });`, 167 | output: `5
168 | 1
169 | 8` 170 | }, 171 | { 172 | name: 'map', 173 | shortDesc: 174 | 'creating a new array from each element with a function I create', 175 | desc: 176 | 'Creates a new array with the results of calling a provided function on every element in this array.', 177 | example: `let map = arr.map(x => x + 1);
178 | console.log(map);`, 179 | output: `[6, 2, 9]` 180 | }, 181 | { 182 | name: 'entries', 183 | shortDesc: 'creating an iterator object', 184 | desc: 185 | 'Returns a new Array Iterator object that contains the key/value pairs for each index in the array. There are a lot of uses for iterators, as well as other methods used with it in conjuction, like values and keys', 186 | example: `let iterator = arr.entries();
187 | console.log(iterator.next().value);`, 188 | output: `[0, 5]
189 | // the 0 is the index,
190 | // the 5 is the first number` 191 | } 192 | ], 193 | find: { 194 | single: [ 195 | { 196 | name: 'includes', 197 | shortDesc: 'out if a certain element exists', 198 | desc: 199 | 'Determines whether an array contains a certain element, returning true or false as appropriate.', 200 | example: `console.log(arr.includes(1));`, 201 | output: `true` 202 | }, 203 | { 204 | name: 'indexOf', 205 | shortDesc: 'the first index of a particular item', 206 | desc: 207 | 'Returns the first index at which a given element can be found in the array, or -1 if it is not present.', 208 | example: `console.log(arr.indexOf(5));`, 209 | output: `0` 210 | }, 211 | { 212 | name: 'lastIndexOf', 213 | shortDesc: 'the last index of a particular item', 214 | desc: 215 | 'Returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found.', 216 | example: `console.log(arr.lastIndexOf(5));`, 217 | output: `0` 218 | }, 219 | { 220 | name: 'find', 221 | shortDesc: 'the first element that satisfies a condition', 222 | desc: 223 | 'Returns the found value in the array, if an element in the array satisfies the provided testing function or undefined if not found. Similar to findIndex(), but it returns the item instead of the index.', 224 | example: `let isTiny = (el) => el < 2;
225 | console.log(arr.find(isTiny));`, 226 | output: `1` 227 | }, 228 | { 229 | name: 'findIndex', 230 | shortDesc: 'the first index of an item that satisfies a condition', 231 | desc: 232 | 'Returns the index of the first element in the array that satisfies the provided testing function. Otherwise -1 is returned. Similar to find(), but it returns the index instead of the item.', 233 | example: `let isBig = (el) => el > 6;
234 | console.log(arr.findIndex(isBig));`, 235 | output: `2` 236 | }, 237 | { 238 | name: 'reduce', 239 | shortDesc: 'a value by reducing the Array, start to finish', 240 | desc: 241 | 'Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.', 242 | example: `let reducer = (a, b) => a + b;
243 | console.log(arr.reduce(reducer));`, 244 | output: `14` 245 | }, 246 | { 247 | name: 'reduceRight', 248 | shortDesc: 'a value by reducing the Array, finish to start', 249 | desc: 250 | 'Apply a function against an accumulator and each value of the array (from right-to-left) as to reduce it to a single value.', 251 | example: `[arr, [0, 1]].reduceRight((a, b) => {
252 |   return a.concat(b)
253 | }, [])`, 254 | output: `[0, 1, 5, 1, 8]` 255 | } 256 | ], 257 | many: [ 258 | { 259 | name: 'filter', 260 | shortDesc: 'values based on a condition I create', 261 | desc: 262 | 'Creates a new array with all of the elements of this array for which the provided filtering function returns true.', 263 | example: `let filtered = arr.filter(el => el > 4);
264 | console.log(filtered)`, 265 | output: `[5, 8]` 266 | }, 267 | { 268 | name: 'every', 269 | shortDesc: 'whether or not every item satisfies a condition', 270 | desc: 271 | 'Returns true if every element in this array satisfies the provided testing function.', 272 | example: `let isSmall = (el) => el < 10;
273 | console.log(arr.every(isSmall));`, 274 | output: `true` 275 | }, 276 | { 277 | name: 'some', 278 | shortDesc: 'whether or not at least one item satisfies a condition', 279 | desc: 280 | 'Returns true if at least one element in this array satisfies the provided testing function.', 281 | example: `let biggerThan4 = (el) => el > 4;
282 | console.log(arr.some(biggerThan4));`, 283 | output: `true` 284 | } 285 | ] 286 | } 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /src/store/es.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: 'elemento/s en un array', 8 | desc: 'Añade y/o elimina elementos de un array.', 9 | example: `arr.splice(2, 0, 'tacos');
10 | console.log(arr);`, 11 | output: `[5, 1, 'tacos', 8]` 12 | }, 13 | { 14 | name: 'push', 15 | shortDesc: 'elementos al final de un array', 16 | desc: 17 | 'Añade uno o más elementos al final de un array y devuelve la nueva longitud del array.', 18 | example: `arr.push(2);
19 | console.log(arr);`, 20 | output: '[5, 1, 8, 2]' 21 | }, 22 | { 23 | name: 'unshift', 24 | shortDesc: 'elementos al principio de un array', 25 | desc: 26 | 'Añade uno o más elementos al principio de un array y devuelve la nueva longitud del array.', 27 | example: `arr.unshift(2, 7);
28 | console.log(arr);`, 29 | output: '[2, 7, 5, 1, 8]' 30 | }, 31 | { 32 | name: 'concat', 33 | shortDesc: 'este array con otro(s) array(s) y/o valor(es)', 34 | desc: 35 | 'Devuelve un nuevo array compuesto por este array unido a otro(s) array(s) y/o valor(es).', 36 | example: `let arr2 = ['a', 'b', 'c'];
37 | let arr3 = arr.concat(arr2);
38 | console.log(arr);`, 39 | output: `[5, 1, 8, 'a', 'b', 'c']` 40 | } 41 | ], 42 | removing: [ 43 | { 44 | name: 'splice', 45 | shortDesc: 'elemento/s en un array', 46 | desc: 'Añade y/o elimina elementos de un array.', 47 | example: `arr.splice(2, 1);
48 | console.log(arr);`, 49 | output: `[5, 1]` 50 | }, 51 | { 52 | name: 'pop', 53 | shortDesc: 'el último elemento del array', 54 | desc: 'Elimina el último elemento de un array y lo devuelve.', 55 | example: `arr.pop();
56 | console.log(arr);`, 57 | output: `[5, 1]` 58 | }, 59 | { 60 | name: 'shift', 61 | shortDesc: 'el primer elemento del array', 62 | desc: 'Elimina el primer elemento de un array y lo devuelve.', 63 | example: `arr.shift();
64 | console.log(arr);`, 65 | output: `[1, 8]` 66 | }, 67 | { 68 | name: 'slice', 69 | shortDesc: 70 | 'uno o más elementos en orden de uso, dejando el array como está', 71 | desc: 72 | 'El método slice() devuelve una copia de una parte del array dentro de un nuevo array. Puede especificar sólo el elemento final (donde el inicio será cero) o el principio y el final separados por comas. El array original no se modificará.', 73 | example: `let slicedArr = arr.slice(1);
74 | console.log(arr);
75 | console.log(slicedArr);`, 76 | output: `[5, 1, 8]
77 | [1, 8]` 78 | } 79 | ], 80 | string: [ 81 | { 82 | name: 'join', 83 | shortDesc: 'unir todos los elementos del array en una cadena', 84 | desc: `Une todos los elementos de un array en una cadena. Puede unirlo como está o con algo intermedio (un separador), elements.join(' - ') le da foo - bar`, 85 | example: `arr.join();
86 | console.log(arr);`, 87 | output: `"5,1,8"` 88 | }, 89 | { 90 | name: 'toString', 91 | shortDesc: 'devolver una cadena de caracteres representando el array.', 92 | desc: 93 | 'Devuelve una cadena de caracteres que representa el array y sus elementos.', 94 | example: `arr.toString();
95 | console.log(arr);`, 96 | output: `"5,1,8"` 97 | }, 98 | { 99 | name: 'toLocaleString', 100 | shortDesc: 101 | 'devolver la representación del array como una cadena utilizando la configuración regional.', 102 | desc: 103 | 'Este es un poco loco. Devuelve la representación del array como una cadena utilizando la configuración regional. Esto es muy útil para fechas y moneda y tiene algunas extrañas abstracciones nativas, por lo que es mejor consultar los documentos al utilizarlo.', 104 | example: `let date = [new Date()];
105 | const arrString = arr.toLocaleString();
106 | const dateString = date.toLocaleString();
107 | console.log(arrString, dateString);`, 108 | output: `"5,1,8 12/26/2017, 6:54:49 PM"` 109 | } 110 | ], 111 | ordering: [ 112 | { 113 | name: 'reverse', 114 | shortDesc: 'invertir el orden del array', 115 | desc: 116 | 'Invierte el orden de los elementos de un array - el primero se convierte en el último, y el último en el primero.', 117 | example: `arr.reverse();
118 | console.log(arr);`, 119 | output: `[8, 1, 5]` 120 | }, 121 | { 122 | name: 'sort', 123 | shortDesc: 'ordenar los elementos del array', 124 | desc: 'Ordena los elementos de un array y lo devuelve.', 125 | example: `arr.sort();
126 | console.log(arr);`, 127 | output: `[1, 5, 8]` 128 | } 129 | ], 130 | other: [ 131 | { 132 | name: 'length', 133 | shortDesc: 'encontrar la longitud del array', 134 | desc: 'Devuelve el número de elementos en ese array.', 135 | example: `console.log(arr.length);`, 136 | output: `3` 137 | }, 138 | { 139 | name: 'fill', 140 | shortDesc: 'llenar todos los elementos del array con un valor estático', 141 | desc: 142 | 'Llena todos los elementos de un array desde un índice inicial hasta un índice final con un valor estático.', 143 | example: `arr.fill(2);
144 | console.log(arr);`, 145 | output: `[2, 2, 2]` 146 | }, 147 | { 148 | name: 'copyWithin', 149 | shortDesc: 150 | 'copiar una secuencia de elementos del array dentro del array.', 151 | desc: 152 | 'Copia una secuencia de elementos del array dentro del array. Puede especificar sólo el elemento final (donde el inicio será cero) o el principio y el final separados por comas.', 153 | example: `arr.copyWithin(1);
154 | console.log(arr);`, 155 | output: `[5, 5, 1]` 156 | } 157 | ], 158 | iterate: [ 159 | { 160 | name: 'forEach', 161 | shortDesc: 'ejecutar una función creada para cada elemento', 162 | desc: 163 | 'El método forEach() ejecuta una función determinada para cada elemento del array.', 164 | example: `arr.forEach((element) => {
165 |   console.log(element)
166 | });`, 167 | output: `5
168 | 1
169 | 8` 170 | }, 171 | { 172 | name: 'map', 173 | shortDesc: 174 | 'crear un nuevo array a partir de cada elemento con una función creada por el usuario', 175 | desc: 176 | 'Crea un nuevo array con los resultados de la llamada a la función indicada aplicados a cada uno de sus elementos.', 177 | example: `let map = arr.map(x => x + 1);
178 | console.log(map);`, 179 | output: `[6, 2, 9]` 180 | }, 181 | { 182 | name: 'entries', 183 | shortDesc: 'crear un objeto iterador', 184 | desc: 185 | 'Devuelve un nuevo objeto Array Iterator que contiene los pares clave/valor para cada índice de la matriz. Hay muchos usos para los iteradores, así como otros métodos utilizados con ellos en conjunto, como values y keys.', 186 | example: `let iterator = arr.entries();
187 | console.log(iterator.next().value);`, 188 | output: `[0, 5]
189 | // the 0 is the index,
190 | // the 5 is the first number` 191 | } 192 | ], 193 | find: { 194 | single: [ 195 | { 196 | name: 'includes', 197 | shortDesc: 'si existe un elemento determinado', 198 | desc: 199 | 'Determina si un array contiene un elemento determinado, devolviendo verdadero o falso según corresponda.', 200 | example: `console.log(arr.includes(1));`, 201 | output: `true` 202 | }, 203 | { 204 | name: 'indexOf', 205 | shortDesc: 206 | 'el primer índice en el que se puede encontrar un elemento', 207 | desc: 208 | 'Devuelve el primer índice en el que se puede encontrar un elemento dado en el array, o -1 si no está presente.', 209 | example: `console.log(arr.indexOf(5));`, 210 | output: `0` 211 | }, 212 | { 213 | name: 'lastIndexOf', 214 | shortDesc: 215 | 'el ultimo índice en el que se puede encontrar un elemento', 216 | desc: 217 | 'Devuelve el último índice (máximo) de un elemento dentro del array igual al valor especificado, o -1 si no se encuentra ninguno.', 218 | example: `console.log(arr.indexOf(5));`, 219 | output: `0` 220 | }, 221 | { 222 | name: 'find', 223 | shortDesc: 'el primer elemento que satisface una condición', 224 | desc: 225 | 'Devuelve el valor encontrado en el array, si un elemento del array satisface la función de prueba provista o undefined si no se encuentra. Similar a findIndex(), pero devuelve el ítem en lugar del índice.', 226 | example: `let isTiny = (el) => el < 2;
227 | console.log(arr.find(isTiny));`, 228 | output: `1` 229 | }, 230 | { 231 | name: 'findIndex', 232 | shortDesc: 233 | 'el primer índice de un artículo que satisface una condición', 234 | desc: 235 | 'Devuelve el índice del primer elemento del array que satisface la función de prueba proporcionada. De lo contrario, se devuelve -1. Similar a find(), pero devuelve el índice en lugar del elemento.', 236 | example: `let isBig = (el) => el > 6;
237 | console.log(arr.findIndex(isBig));`, 238 | output: `2` 239 | }, 240 | { 241 | name: 'reduce', 242 | shortDesc: 'un valor para reducir el Array, de principio a fin', 243 | desc: 244 | 'Aplica una función a un acumulador y a cada valor de un array (de izquierda a derecha) para reducirlo a un único valor.', 245 | example: `let reducer = (a, b) => a + b;
246 | console.log(arr.reduce(reducer));`, 247 | output: `14` 248 | }, 249 | { 250 | name: 'reduceRight', 251 | shortDesc: 'un valor para reducir el Array, de fin a principio', 252 | desc: 253 | 'Aplica una función a un acumulador y a cada valor de un array (de derecha a izquierda) para reducirlo a un único valor.', 254 | example: `[arr, [0, 1]].reduceRight((a, b) => {
255 |   return a.concat(b)
256 | }, [])`, 257 | output: `[0, 1, 5, 1, 8]` 258 | } 259 | ], 260 | many: [ 261 | { 262 | name: 'filter', 263 | shortDesc: 'valores basados en una condición que usted crea', 264 | desc: 265 | 'Crea un nuevo array con todos los elementos de este array para el cual la función de filtrado proporcionada devuelve true.', 266 | example: `let filtered = arr.filter(el => el > 4);
267 | console.log(filtered)`, 268 | output: `[5, 8]` 269 | }, 270 | { 271 | name: 'every', 272 | shortDesc: 'si cada elemento satisface o no una condición', 273 | desc: 274 | 'Devuelve true si cada elemento de este array satisface la función de prueba proporcionada.', 275 | example: `let isSmall = (el) => el < 10;
276 | console.log(arr.every(isSmall));`, 277 | output: `true` 278 | }, 279 | { 280 | name: 'some', 281 | shortDesc: 'si un elemento cumple o no al menos una condición', 282 | desc: 283 | 'Devuelve true si al menos un elemento de este array satisface la función de prueba proporcionada.', 284 | example: `let biggerThan4 = (el) => el > 4;
285 | console.log(arr.some(biggerThan4));`, 286 | output: `true` 287 | } 288 | ] 289 | } 290 | } 291 | } 292 | -------------------------------------------------------------------------------- /src/store/fr.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: 'un ou des éléments à un tableau', 8 | desc: 9 | "Modifie le contenu d'un tableau en retirant des éléments et/ou en ajoutant de nouveaux éléments.", 10 | example: `arr.splice(2, 0, 'tacos');
11 | console.log(arr);`, 12 | output: `[5, 1, 'tacos', 8]` 13 | }, 14 | { 15 | name: 'push', 16 | shortDesc: "un ou des éléments à la fin d'un tableau", 17 | desc: 18 | "Ajoute un ou plusieurs éléments à la fin d'un tableau et retourne la nouvelle taille du tableau.", 19 | example: `arr.push(2);
20 | console.log(arr);`, 21 | output: '[5, 1, 8, 2]' 22 | }, 23 | { 24 | name: 'unshift', 25 | shortDesc: "un ou des éléments au début d'un tableau", 26 | desc: 27 | "Ajoute un ou plusieurs éléments au début d'un tableau et renvoie la nouvelle longueur du tableau.", 28 | example: `arr.unshift(2, 7);
29 | console.log(arr);`, 30 | output: '[2, 7, 5, 1, 8]' 31 | }, 32 | { 33 | name: 'concat', 34 | shortDesc: "ce tableau à d'autre(s) tableau(x) et/ou valeur(s)", 35 | desc: 36 | "Renvoie un nouveau tableau qui est le résultat de la concaténation d'un ou plusieurs tableaux.", 37 | example: `let arr2 = ['a', 'b', 'c'];
38 | let arr3 = arr.concat(arr2);
39 | console.log(arr3);`, 40 | output: `[5, 1, 8, 'a', 'b', 'c']` 41 | } 42 | ], 43 | removing: [ 44 | { 45 | name: 'splice', 46 | shortDesc: 'un ou des éléments à un tableau', 47 | desc: 48 | "Modifie le contenu d'un tableau en retirant des éléments et/ou en ajoutant de nouveaux éléments.", 49 | example: `arr.splice(2, 1);
50 | console.log(arr);`, 51 | output: `[5, 1]` 52 | }, 53 | { 54 | name: 'pop', 55 | shortDesc: "le dernier élément d'un tableau", 56 | desc: 57 | "Supprime le dernier élément d'un tableau et retourne cet élément.", 58 | example: `arr.pop();
59 | console.log(arr);`, 60 | output: `[5, 1]` 61 | }, 62 | { 63 | name: 'shift', 64 | shortDesc: "le premier élément d'un tableau", 65 | desc: 66 | "Supprime le premier élément d'un tableau et retourne cet élément.", 67 | example: `arr.shift();
68 | console.log(arr);`, 69 | output: `[1, 8]` 70 | }, 71 | { 72 | name: 'slice', 73 | shortDesc: 74 | "un ou plusieurs éléments successifs, sans modifier le tableau d'origine", 75 | desc: 76 | "Renvoie un objet tableau, contenant une copie superficielle (shallow copy) d'une portion du tableau d'origine. Il est possible de spécifier juste l'indice de début (et l'indice de fin sera la longueur du tableau) ou les deux indices (début et fin, séparés par une virgule). Le tableau original ne sera pas modifié.", 77 | example: `let slicedArr = arr.slice(1);
78 | console.log(arr);
79 | console.log(slicedArr);`, 80 | output: `[5, 1, 8]
81 | [1, 8]` 82 | } 83 | ], 84 | string: [ 85 | { 86 | name: 'join', 87 | shortDesc: 88 | "de concaténer tous les éléments d'un tableau dans une chaîne de caractères", 89 | desc: `Concaténe tous les éléments d'un tableau dans une chaîne de caractères et renvoie cette nouvelle chaîne de caractères. Il est possible de concaténer tel quel ou avec un séparateur, elements.join(' - ') renvoie foo - bar`, 90 | example: `console.log(arr.join());`, 91 | output: `"5,1,8"` 92 | }, 93 | { 94 | name: 'toString', 95 | shortDesc: 96 | 'de retourner une chaîne de caractères représentant le tableau', 97 | desc: 98 | 'Renvoie une chaîne de caractères représentant le tableau spécifié et ses éléments.', 99 | example: `console.log(arr.toString());`, 100 | output: `"5,1,8"` 101 | }, 102 | { 103 | name: 'toLocaleString', 104 | shortDesc: 105 | 'de retourner une chaîne de caractères localisée représentant le tableau', 106 | desc: 107 | "Cette méthode est un peu touchy. Renvoie une chaîne de caractères localisée représentant le tableau spécifié et ses éléments. C'est vraiment utile pour les dates et les devises ! Le mieux est de consulter la documentation quand on souhaite l'utiliser car certains comportements sont étranges.", 108 | example: `let date = [new Date()];
109 | arr.toLocaleString();
110 | date.toLocaleString();
111 | console.log(arr, date);`, 112 | output: `"5,1,8 12/26/2017, 6:54:49 PM"` 113 | } 114 | ], 115 | ordering: [ 116 | { 117 | name: 'reverse', 118 | shortDesc: "d'inverser l'ordre d'un tableau", 119 | desc: 120 | "Inverse l'ordre d'un tableau : le premier élément devient le dernier et le dernier devient le premier et ainsi de suite.", 121 | example: `arr.reverse();
122 | console.log(arr);`, 123 | output: `[8, 1, 5]` 124 | }, 125 | { 126 | name: 'sort', 127 | shortDesc: "de trier les éléments d'un tableau", 128 | desc: `Trie les éléments d'un tableau, dans ce même tableau, et renvoie le tableau. 129 |
130 | Note importante : Si aucune fonction de comparaison n'est fournie, les éléments sont triés en les convertisant en chaîne de caractères et en les comparant à partir du point de code Unicode. Par exemple, "Banana" vient avant "cherry". Dans un tri numérique, 9 vient avant 80, parceque les nombres sont convertis en chaîne de caractères, "80" vient avant "9" dans l'odre Unicode. La documentation contient plus d'informations à ce sujet.`, 131 | example: `arr.sort();
132 | console.log(arr);`, 133 | output: `[1, 5, 8]` 134 | } 135 | ], 136 | other: [ 137 | { 138 | name: 'length', 139 | shortDesc: "de trouver la taille d'un tableau", 140 | desc: "Retourne le nombre d'éléments présents dans le tableau.", 141 | example: `console.log(arr.length);`, 142 | output: `3` 143 | }, 144 | { 145 | name: 'fill', 146 | shortDesc: 147 | "de remplir tous les éléments d'un tableau avec une valeur statique", 148 | desc: 149 | "Remplit tous les éléments d'un tableau entre deux indices avec une valeur statique.", 150 | example: `arr.fill(2);
151 | console.log(arr);`, 152 | output: `[2, 2, 2]` 153 | }, 154 | { 155 | name: 'copyWithin', 156 | shortDesc: "de copier une partie d'un tableau", 157 | desc: 158 | "Effectue une copie superficielle (shallow copy) d'une partie d'un tableau sur ce même tableau et le renvoie, sans modifier sa taille.", 159 | example: `arr.copyWithin(1);
160 | console.log(arr);`, 161 | output: `[5, 5, 1]` 162 | } 163 | ], 164 | iterate: [ 165 | { 166 | name: 'forEach', 167 | shortDesc: 'exécutant une fonction sur chaque élément', 168 | desc: 'Exécute une fonction donnée sur chaque élément du tableau.', 169 | example: `arr.forEach((element) => {
170 |   console.log(element)
171 | });`, 172 | output: `5
173 | 1
174 | 8` 175 | }, 176 | { 177 | name: 'map', 178 | shortDesc: 179 | 'créant un nouveau tableau depuis chaque élément via une fonction', 180 | desc: 181 | "Crée un nouveau tableau composé des résultats d'une fonction donnée en argument sur chaque élément du tableau.", 182 | example: `let map = arr.map(x => x + 1);
183 | console.log(map);`, 184 | output: `[6, 2, 9]` 185 | }, 186 | { 187 | name: 'entries', 188 | shortDesc: 'créant un objet Array Iterator', 189 | desc: 190 | "Renvoie un nouvel objet de type Array Iterator qui contient le couple clef/valeur pour chaque élément du tableau. Il y a beaucoup de cas d'utilisation des iterators, mais aussi les autres méthodes à utiliser comme values et keys", 191 | example: `let iterator = arr.entries();
192 | console.log(iterator.next().value);`, 193 | output: `[0, 5]
194 | // the 0 is the index,
195 | // the 5 is the first number` 196 | } 197 | ], 198 | find: { 199 | single: [ 200 | { 201 | name: 'includes', 202 | shortDesc: 'si un élément existe', 203 | desc: 204 | "Permet de déterminer si un tableau contient un élément et renvoie true si c'est le cas, false sinon.", 205 | example: `console.log(arr.includes(1));`, 206 | output: `true` 207 | }, 208 | { 209 | name: 'indexOf', 210 | shortDesc: "le premier indice d'un élément en particulier", 211 | desc: 212 | "Renvoie le premier indice pour lequel on trouve un élément donné dans un tableau. Si l'élément cherché n'est pas présent dans le tableau, la méthode renverra -1.", 213 | example: `console.log(arr.indexOf(5));`, 214 | output: `0` 215 | }, 216 | { 217 | name: 'lastIndexOf', 218 | shortDesc: "le dernier indice d'un élément en particulier", 219 | desc: 220 | "Permet de renvoyer le dernier indice pour lequel une valeur donnée est présente dans un tableau. Si la valeur recherchée n'est pas présente, le résultat sera -1.", 221 | example: `console.log(arr.lastIndexOf(5));`, 222 | output: `0` 223 | }, 224 | { 225 | name: 'find', 226 | shortDesc: 'le premier élément qui respecte une condition', 227 | desc: 228 | "Renvoie la valeur du premier élément trouvé dans le tableau qui respecte la condition donnée par la fonction de test passée en argument. Sinon, la valeur undefined est renvoyée. Similaire à findIndex(), mais retourne l'élément au lieu de l'indice.", 229 | example: `let isTiny = (el) => el < 2;
230 | console.log(arr.find(isTiny));`, 231 | output: `1` 232 | }, 233 | { 234 | name: 'findIndex', 235 | shortDesc: 'le premier indice qui respecte une condition', 236 | desc: 237 | "Renvoie l'indice du premier élément du tableau qui satisfait une condition donnée par une fonction. Si la fonction renvoie false pour tous les éléments du tableau, le résultat vaut -1. Similaire à find(), mais retourne l'indice au lieu de l'élément.", 238 | example: `let isBig = (el) => el > 6;
239 | console.log(arr.findIndex(isBig));`, 240 | output: `2` 241 | }, 242 | { 243 | name: 'reduce', 244 | shortDesc: 'une valeur en réduisant le tableau, du début à la fin', 245 | desc: 246 | "Applique une fonction qui est un accumulateur et qui traite chaque valeur d'une liste (de la gauche vers la droite) afin de la réduire à une seule valeur.", 247 | example: `let reducer = (a, b) => a + b;
248 | console.log(arr.reduce(reducer));`, 249 | output: `14` 250 | }, 251 | { 252 | name: 'reduceRight', 253 | shortDesc: 'une valeur en réduisant le tableau, de la fin au début', 254 | desc: 255 | "Applique une fonction qui est un accumulateur et qui traite chaque valeur d'une liste (de la droite vers la gauche) afin de la réduire à une seule valeur.", 256 | example: `[arr, [0, 1]].reduceRight((a, b) => {
257 |   return a.concat(b)
258 | }, [])`, 259 | output: `[0, 1, 5, 1, 8]` 260 | } 261 | ], 262 | many: [ 263 | { 264 | name: 'filter', 265 | shortDesc: 'des éléments basés sur une condition', 266 | desc: 267 | "Crée et retourne un nouveau tableau contenant tous les éléments du tableau d'origine qui remplissent une condition déterminée par la fonction callback.", 268 | example: `let filtered = arr.filter(el => el > 4);
269 | console.log(filtered)`, 270 | output: `[5, 8]` 271 | }, 272 | { 273 | name: 'every', 274 | shortDesc: 'si oui ou non tous les éléments respectent une condition', 275 | desc: 276 | "Permet de tester si tous les éléments d'un tableau vérifient une condition donnée par une fonction en argument.", 277 | example: `let isSmall = (el) => el < 10;
278 | console.log(arr.every(isSmall));`, 279 | output: `true` 280 | }, 281 | { 282 | name: 'some', 283 | shortDesc: 'si oui ou non au moins un élément respecte une condition', 284 | desc: 285 | 'Teste si au moins un élément du tableau passe le test implémenté par la fonction fournie.', 286 | example: `let biggerThan4 = (el) => el > 4;
287 | console.log(arr.some(biggerThan4));`, 288 | output: `true` 289 | } 290 | ] 291 | } 292 | } 293 | } 294 | -------------------------------------------------------------------------------- /src/store/id.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: 'satu atau lebih elemen ke sebuah array', 8 | desc: 'Menambah dan/atau menghilangkan satu atau lebih elemen dari sebuah array.', 9 | example: `arr.splice(2, 0, 'tacos');
10 | console.log(arr);`, 11 | output: `[5, 1, 'tacos', 8]` 12 | }, 13 | { 14 | name: 'push', 15 | shortDesc: 'satu atau lebih elemen pada posisi akhir dari sebuah array', 16 | desc: 17 | 'Menambah satu atau lebih elemen pada posisi akhir dari sebuah array dan mengembalikan panjang array yang baru.', 18 | example: `arr.push(2);
19 | console.log(arr);`, 20 | output: '[5, 1, 8, 2]' 21 | }, 22 | { 23 | name: 'unshift', 24 | shortDesc: 'satu atau lebih elemen pada posisi awal dari sebuah array', 25 | desc: 26 | 'Menambah satu atau lebih elemen pada posisi awal dari sebuah array dan mengembalikan panjang array yang baru.', 27 | example: `arr.unshift(2, 7);
28 | console.log(arr);`, 29 | output: '[2, 7, 5, 1, 8]' 30 | }, 31 | { 32 | name: 'concat', 33 | shortDesc: 'array yang dipanggil ke satu atau lebih array dan/atau nilai lain', 34 | desc: 35 | 'Mengembalikan sebuah array yang terdiri dari array yang dipanggil dan digabung dengan satu atau lebih array dan/atau nilai lain.', 36 | example: `let arr2 = ['a', 'b', 'c'];
37 | let arr3 = arr.concat(arr2);
38 | console.log(arr3);`, 39 | output: `[5, 1, 8, 'a', 'b', 'c']` 40 | } 41 | ], 42 | removing: [ 43 | { 44 | name: 'splice', 45 | shortDesc: 'satu atau lebih elemen dari sebuah array', 46 | desc: 'Menambah dan/atau menghapus satu atau lebih elemen dari sebuah array.', 47 | example: `arr.splice(2, 1);
48 | console.log(arr);`, 49 | output: `[5, 1]` 50 | }, 51 | { 52 | name: 'pop', 53 | shortDesc: 'elemen terakhir dari array', 54 | desc: 55 | 'Menghapus elemen terakhir dari sebuah array dan mengembalikan elemen tersebut.', 56 | example: `arr.pop();
57 | console.log(arr);`, 58 | output: `[5, 1]` 59 | }, 60 | { 61 | name: 'shift', 62 | shortDesc: 'elemen pertama dari array', 63 | desc: 64 | 'Menghapus elemen pertama dari sebuah array dan mengembalikan elemen tersebut.', 65 | example: `arr.shift();
66 | console.log(arr);`, 67 | output: `[1, 8]` 68 | }, 69 | { 70 | name: 'slice', 71 | shortDesc: 72 | 'satu atau lebih elemen secara berurutan untuk digunakan, tanpa memodifikasi array asli', 73 | desc: 74 | 'Metode slice() mengembalikan shallow copy dari suatu bagian array ke sebuah objek array baru. Anda dapat memberi spesifikasi elemen awalnya saja (di mana nilai posisi akhir akan sesuai dengan panjang array) atau kedua posisi awal dan akhir, dengan koma sebagai pemisahnya. Array yang asli tidak akan dimodifikasi.', 75 | example: `let slicedArr = arr.slice(1);
76 | console.log(arr);
77 | console.log(slicedArr);`, 78 | output: `[5, 1, 8]
79 | [1, 8]` 80 | } 81 | ], 82 | string: [ 83 | { 84 | name: 'join', 85 | shortDesc: 'menggabungkan semua elemen dari sebuah array menjadi sebuah string', 86 | desc: `menggabungkan semua elemen dari sebuah array menjadi sebuah string. Anda juga dapat menggabungkannya dengan menggunakan sebuah pemisah di antara elemen-elemen tersebut. Sebagai contoh, elements.join(' - 87 | ') akan menghasilkan foo-bar`, 88 | example: `console.log(arr.join());`, 89 | output: `"5,1,8"` 90 | }, 91 | { 92 | name: 'toString', 93 | shortDesc: 'mengembalikan sebuah string yang merepresentasikan array', 94 | desc: 'Mengembalikan sebuah string yang merepresentasikan array dan elemen-elemen array tersebut.', 95 | example: `console.log(arr.toString());`, 96 | output: `"5,1,8"` 97 | }, 98 | { 99 | name: 'toLocaleString', 100 | shortDesc: 'mengembalikan sebuah string yang telah dilokalisasi yang merepresentasikan array', 101 | desc: 102 | 'Mengembalikan sebuah string yang telah dilokalisasi yang merepresentasikan array beserta elemen-elemennya. Metode ini berguna untuk tanggal-tanggal dan mata uang, serta memiliki abstraksi native yang cukup aneh, sehingga sebaiknya Anda membaca dokumentasinya ketika menggunakannya.', 103 | example: `let date = [new Date()];
104 | const arrString = arr.toLocaleString();
105 | const dateString = date.toLocaleString();
106 | console.log(arrString, dateString);`, 107 | output: `"5,1,8 12/26/2017, 6:54:49 PM"` 108 | } 109 | ], 110 | ordering: [ 111 | { 112 | name: 'reverse', 113 | shortDesc: 'membalikkan urutan dari array', 114 | desc: 115 | 'Mengembalikan urutan dari elemen-elemen yang ada pada array di tempat — elemen pertama menjadi yang terakhir, dan elemen yang terakhir menjadi yang pertama.', 116 | example: `arr.reverse();
117 | console.log(arr);`, 118 | output: `[8, 1, 5]` 119 | }, 120 | { 121 | name: 'sort', 122 | shortDesc: 'mengurutkan item-item pada array', 123 | desc: `Mengurutkan elemen-elemen dari sebuah array di tempat dan mengembalikan array tersebut.
124 |
125 | Catatan penting: Apabila compareFunction tidak diberikan, maka elemen-elemen akan diurutkan dengan cara mengubah elemen-elemen tersebut menjadi string, dan membandingkan string-string tersebut dengan mengacu pada urutan Unicode code point. Sebagai contoh, "Banana" ditempatkan sebelum "cherry". Dalam urutan numerik, 9 ditempatkan sebelum 80, namun karena angka-angka diubah menjadi string, maka "80" ditempatkan sebelum "9" sesuai dengan urutan Unicode. Dokumentasi metode ini mempunyai lebih banyak informasi untuk memperjelas.`, 126 | example: `arr.sort();
127 | console.log(arr);`, 128 | output: `[1, 5, 8]` 129 | } 130 | ], 131 | other: [ 132 | { 133 | name: 'length', 134 | shortDesc: 'menemukan panjang dari array', 135 | desc: 'Mengembalikan jumlah elemen pada array.', 136 | example: `console.log(arr.length);`, 137 | output: `3` 138 | }, 139 | { 140 | name: 'fill', 141 | shortDesc: 'mengisi semua elemen dari array dengan sebuah nilai statis', 142 | desc: 143 | 'Mengisi semua elemen dari sebuah array mulai dari indeks awal sampai indeks terakhir dengan sebuah nilai statis.', 144 | example: `arr.fill(2);
145 | console.log(arr);`, 146 | output: `[2, 2, 2]` 147 | }, 148 | { 149 | name: 'copyWithin', 150 | shortDesc: 'menyalin sebuah urutan dari elemen-elemen array di dalam array', 151 | desc: 152 | 'Menyalin sebuah urutan dari elemen-elemen array di dalam array. Anda dapat memberi spesifikasi elemen akhirnya saja (di mana posisi awal akan dimulai dari nol) atau kedua posisi awal dan akhir, dengan koma sebagai pemisahnya.', 153 | example: `arr.copyWithin(1);
154 | console.log(arr);`, 155 | output: `[5, 5, 1]` 156 | } 157 | ], 158 | iterate: [ 159 | { 160 | name: 'forEach', 161 | shortDesc: 'mengeksekusi sebuah fungsi yang saya buat untuk masing-masing elemen', 162 | desc: 163 | 'Metode forEach() mengeksekusi fungsi yang diberikan, satu kali untuk masing-masing elemen pada array.', 164 | example: `arr.forEach((element) => {
165 |   console.log(element)
166 | });`, 167 | output: `5
168 | 1
169 | 8` 170 | }, 171 | { 172 | name: 'map', 173 | shortDesc: 174 | 'membuat array baru dari masing-masing elemen dengan menggunakan fungsi yang saya buat', 175 | desc: 176 | 'Membuat sebuah array baru. Array baru ini berisi hasil-hasil pemanggilan fungsi yang diberikan pada setiap elemen di dalam array.', 177 | example: `let map = arr.map(x => x + 1);
178 | console.log(map);`, 179 | output: `[6, 2, 9]` 180 | }, 181 | { 182 | name: 'entries', 183 | shortDesc: 'membuat sebuah objek iterator', 184 | desc: 185 | 'Mengembalikan sebuah objek Array Iterator baru yang berisi pasangan-pasangan key/value untuk masing-masing indeks di dalam array. Ada banyak kegunaan iterator beserta metode-metode yang berhubungan dengan iterator, seperti values dan keys', 186 | example: `let iterator = arr.entries();
187 | console.log(iterator.next().value);`, 188 | output: `[0, 5]
189 | // the 0 is the index,
190 | // the 5 is the first number` 191 | } 192 | ], 193 | find: { 194 | single: [ 195 | { 196 | name: 'includes', 197 | shortDesc: 'apakah terdapat suatu elemen tertentu', 198 | desc: 199 | 'Menentukan apakah sebuah array berisi suatu elemen tertentu. Apabila ada, ia akan mengembalikan true. Sebaliknya, ia akan mengembalikan false.', 200 | example: `console.log(arr.includes(1));`, 201 | output: `true` 202 | }, 203 | { 204 | name: 'indexOf', 205 | shortDesc: 'indeks pertama dari sebuah item tertentu', 206 | desc: 207 | 'Mengembalikan indeks pertama di mana suatu elemen yang diberikan dapat ditemukan di dalam array. Ia akan mengembalikan -1 apabila elemen tersebut tidak ada di dalam array.', 208 | example: `console.log(arr.indexOf(5));`, 209 | output: `0` 210 | }, 211 | { 212 | name: 'lastIndexOf', 213 | shortDesc: 'indeks terakhir dari sebuah item tertentu', 214 | desc: 215 | 'Mengembalikan indeks terakhir (terbesar) dari sebuah elemen di dalam array yang sama dengan suatu nilai yang telah ditentukan. Ia akan mengembalikan -1 apabila tidak ada elemen dengan nilai tersebut yang ditemukan.', 216 | example: `console.log(arr.lastIndexOf(5));`, 217 | output: `0` 218 | }, 219 | { 220 | name: 'find', 221 | shortDesc: 'elemen pertama yang memenuhi sebuah kondisi', 222 | desc: 223 | 'Mengembalikan nilai yang ditemukan pada array, apabila elemen tersebut memenuhi fungsi testing yang diberikan atau undefined apabila tidak ditemukan. Serupa dengan findIndex(), namun metode ini mengembalikan item.', 224 | example: `let isTiny = (el) => el < 2;
225 | console.log(arr.find(isTiny));`, 226 | output: `1` 227 | }, 228 | { 229 | name: 'findIndex', 230 | shortDesc: 'indeks pertama dari sebuah item yang memenuhi sebuah kondisi', 231 | desc: 232 | 'Mengembalikan indeks dari elemen pertama pada array yang memenuhi fungsi testing yang diberikan. Apabila tidak ada elemen yang memenuhi kondisi tersebut, maka metode ini akan mengembalikan nilai -1. Serupa dengan find(), namun metode ini mengembalikan indeks dari item.', 233 | example: `let isBig = (el) => el > 6;
234 | console.log(arr.findIndex(isBig));`, 235 | output: `2` 236 | }, 237 | { 238 | name: 'reduce', 239 | shortDesc: 'sebuah nilai dengan cara mereduksi array yang dipanggil, dari awal sampai akhir', 240 | desc: 241 | 'Mengaplikasikan sebuah fungsi terhadap sebuah akumulator dan masing-masing nilai dari array (dari kiri ke kanan) untuk mereduksinya menjadi sebuah nilai.', 242 | example: `let reducer = (a, b) => a + b;
243 | console.log(arr.reduce(reducer));`, 244 | output: `14` 245 | }, 246 | { 247 | name: 'reduceRight', 248 | shortDesc: 'sebuah nilai dengan cara mereduksi array yang dipanggil, dari akhir sampai awal', 249 | desc: 250 | 'Mengaplikasikan sebuah fungsi terhadap sebuah akumulator dan masing-masing nilai dari array (dari kanan ke kiri) untuk mereduksinya menjadi sebuah nilai.', 251 | example: `[arr, [0, 1]].reduceRight((a, b) => {
252 |   return a.concat(b)
253 | }, [])`, 254 | output: `[0, 1, 5, 1, 8]` 255 | } 256 | ], 257 | many: [ 258 | { 259 | name: 'filter', 260 | shortDesc: 'satu atau lebih nilai berdasarkan kondisi yang saya buat', 261 | desc: 262 | 'Membuat sebuah array baru, di mana array baru tersebut terdiri dari seluruh elemen pada array yang memenuhi kondisi yang diberikan.', 263 | example: `let filtered = arr.filter(el => el > 4);
264 | console.log(filtered)`, 265 | output: `[5, 8]` 266 | }, 267 | { 268 | name: 'every', 269 | shortDesc: 'apakah semua item memenuhi suatu kondisi atau tidak', 270 | desc: 271 | 'Mengembalikan true apabila semua elemen pada array memenuhi fungsi testing yang diberikan.', 272 | example: `let isSmall = (el) => el < 10;
273 | console.log(arr.every(isSmall));`, 274 | output: `true` 275 | }, 276 | { 277 | name: 'some', 278 | shortDesc: 'apakah setidaknya sebuah item memenuhi sebuah kondisi', 279 | desc: 280 | 'Mengembalikan true apabila setidaknya sebuah elemen pada array memenuhi fungsi testing yang diberikan.', 281 | example: `let biggerThan4 = (el) => el > 4;
282 | console.log(arr.some(biggerThan4));`, 283 | output: `true` 284 | } 285 | ] 286 | } 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /src/store/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | ar: require('./ar'), 3 | bg: require('./bg'), 4 | cz: require('./cz'), 5 | de: require('./de'), 6 | en: require('./en'), 7 | fr: require('./fr'), 8 | id: require('./id'), 9 | it: require('./it'), 10 | nl: require('./nl'), 11 | pt: require('./pt'), 12 | ru: require('./ru'), 13 | sr: require('./sr'), 14 | ua: require('./ua'), 15 | zh_cn: require('./zh_cn') 16 | } 17 | -------------------------------------------------------------------------------- /src/store/it.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: 'uno o più elementi in un array', 8 | desc: 'Aggunge o rimuove elementi in un array.', 9 | example: `arr.splice(2, 0, 'pizza');
10 | console.log(arr);`, 11 | output: `[5, 1, 'pizza', 8]` 12 | }, 13 | { 14 | name: 'push', 15 | shortDesc: 'elementi alla fine di un array', 16 | desc: 17 | 'Aggiunge uno o più elementi alla fine di un array e restituisce la sua nuova lunghezza.', 18 | example: `arr.push(2);
19 | console.log(arr);`, 20 | output: '[5, 1, 8, 2]' 21 | }, 22 | { 23 | name: 'unshift', 24 | shortDesc: 'elementi all\'inizio di un array', 25 | desc: 26 | 'Aggiunge uno o più elementi all\'inizio di un array e restituisce la sua nuova lunghezza.', 27 | example: `arr.unshift(2, 7);
28 | console.log(arr);`, 29 | output: '[2, 7, 5, 1, 8]' 30 | }, 31 | { 32 | name: 'concat', 33 | shortDesc: 'altri array o valori a un array', 34 | desc: 35 | 'Restituisce un nuovo array composto da questo array unito ad altri array e/o valori.', 36 | example: `let arr2 = ['a', 'b', 'c'];
37 | let arr3 = arr.concat(arr2);
38 | console.log(arr3);`, 39 | output: `[5, 1, 8, 'a', 'b', 'c']` 40 | } 41 | ], 42 | removing: [ 43 | { 44 | name: 'splice', 45 | shortDesc: 'uno o più elementi da un array', 46 | desc: 'Aggunge o rimuove elementi in un array.', 47 | example: `arr.splice(2, 1);
48 | console.log(arr);`, 49 | output: `[5, 1]` 50 | }, 51 | { 52 | name: 'pop', 53 | shortDesc: 'l\'ultimo elemento di un array', 54 | desc: 55 | 'Rimuove l\'ultimo elemento di un array e restituisce tale elemento.', 56 | example: `arr.pop();
57 | console.log(arr);`, 58 | output: `[5, 1]` 59 | }, 60 | { 61 | name: 'shift', 62 | shortDesc: 'il primo elemento di un array', 63 | desc: 64 | 'Rimuove il primo elemento di un array e restituisce tale elemento.', 65 | example: `arr.shift();
66 | console.log(arr);`, 67 | output: `[1, 8]` 68 | }, 69 | { 70 | name: 'slice', 71 | shortDesc: 72 | 'uno o più elementi da un array, lasciado intatto l\'array originale', 73 | desc: 74 | 'La funzione slice() restituisce una copia di parte di un array in un nuovo array, lasciando l\'array originale intatto. Puoi specificare solo l\'elemento di partenza, oppure sia quello di partenza che quello finale, separati da una virgola. L\'array originale non viene modificato.', 75 | example: `let slicedArr = arr.slice(1);
76 | console.log(arr);
77 | console.log(slicedArr);`, 78 | output: `[5, 1, 8]
79 | [1, 8]` 80 | } 81 | ], 82 | string: [ 83 | { 84 | name: 'join', 85 | shortDesc: 'unire tutti gli elementi di un array in una stringa', 86 | desc: `Unisce tutti gli elementi di un arrya in una stringa. Puoi specificare cosa mettere fra gli elementi, altrimenti viene utilizzata una virgola.`, 87 | example: `console.log(arr.join());
88 | console.log(arr.jion(" - "));`, 89 | output: `"5,1,8"
90 | "5 - 1 - 8"` 91 | }, 92 | { 93 | name: 'toString', 94 | shortDesc: 'ottenere una stringa che rappresenti l\'array', 95 | desc: 'Restituisce una stringa che rappresenta l\'array e i suoi elementi', 96 | example: `console.log(arr.toString());`, 97 | output: `"5,1,8"` 98 | }, 99 | { 100 | name: 'toLocaleString', 101 | shortDesc: 'ottenere una stringa localizzata che rappresenti l\'array', 102 | desc: 'Questa è una functione particolare. Restituisce una stringa localizzata che rappresenta l\'array e i suoi elementi; è molto utile quando si lavora con date o valute. Ha un funzionamento complesso, per cui si consiglia di consultare la documentazione quando la si usa.', 103 | example: `let date = [new Date()];
104 | const arrString = arr.toLocaleString();
105 | const dateString = date.toLocaleString();
106 | console.log(arrString);
107 | console.log(dateString);`, 108 | output: `"5,1,8"
109 | "2/1/2018, 00:27:10"` 110 | } 111 | ], 112 | ordering: [ 113 | { 114 | name: 'reverse', 115 | shortDesc: 'invertire l\'ordine di un array', 116 | desc: 117 | 'Inverte l\'ordine degli elementi di un array, modificandolo: il primo diventa l\'ultimo; l\'ultimo diventa il primo.', 118 | example: `arr.reverse();
119 | console.log(arr);`, 120 | output: `[8, 1, 5]` 121 | }, 122 | { 123 | name: 'sort', 124 | shortDesc: 'ordinare gli elementi di un array', 125 | desc: `Ordina gli elementi di un array, modificandolo, e lo restituisce.
126 |
127 | Nota: Se non è specificata nessuna funzione per il confronto, gli elementi sono convertiti in stringhe e ordinati in ordine alfabetico, secondo i codici Unicode corrispondenti ai caratteri. Per esempio, "Banana" viene prima di "ciliegia". In ordine numerico 9 viene prima di 80, ma dal momento che sono convertiti in stringhe "80" viene prima di "9". Vedere la documentazione per ulteriori informazioni.`, 128 | example: `arr.sort();
129 | console.log(arr);`, 130 | output: `[1, 5, 8]` 131 | } 132 | ], 133 | other: [ 134 | { 135 | name: 'length', 136 | shortDesc: 'conoscere la lunghezza di un array', 137 | desc: 'Restituisce il numero di elementi contenuti in un array.', 138 | example: `console.log(arr.length);`, 139 | output: `3` 140 | }, 141 | { 142 | name: 'fill', 143 | shortDesc: 'sostituire tutti gli elementi di un array con un valore dato', 144 | desc: 145 | 'Sostituisce tutti gli elementi di un array, da una posizione iniziale a una finale, con un valore specificato.', 146 | example: `arr.fill(2);
147 | console.log(arr);`, 148 | output: `[2, 2, 2]` 149 | }, 150 | { 151 | name: 'copyWithin', 152 | shortDesc: 'copiare una sequenza di elementi all\'interno di un array', 153 | desc: 154 | 'Copia una sequenza di elementi di un array all\'interno dell\'array stesso. Si può specificare o solo l\'elemento finale (in questo caso viene utilizzato il primo come iniziale), o sia quello iniziale che quello finale, separati da una virgola.', 155 | example: `arr.copyWithin(1);
156 | console.log(arr);`, 157 | output: `[5, 5, 1]` 158 | } 159 | ], 160 | iterate: [ 161 | { 162 | name: 'forEach', 163 | shortDesc: 'eseguire una funzione da me definita per ogni elemento dell\'array', 164 | desc: 165 | 'Esegue una functione specificata una volta per ogni elemento di un array.', 166 | example: `arr.forEach((elemento) => {
167 |   console.log(elemento)
168 | });`, 169 | output: `5
170 | 1
171 | 8` 172 | }, 173 | { 174 | name: 'map', 175 | shortDesc: 176 | 'creare un nuovo array trasformando ogni elemento con una funzione da me definita', 177 | desc: 178 | 'Crea un nuovo array utilizzando i risultati ottenuti richiamando una funzione specificata per ogni elemento dell\'array originale.', 179 | example: `let map = arr.map(x => x + 1);
180 | console.log(map);`, 181 | output: `[6, 2, 9]` 182 | }, 183 | { 184 | name: 'entries', 185 | shortDesc: 'creare un oggetto di tipo Array Iterator', 186 | desc: 187 | 'Restituisce un nuovo oggetto Array Iterator che contiene le coppie chiave/valore per ogni elemento dell\'array. Ci sono molti utilizzi per questo oggetto, e anche altri metodi da utilizzare insieme a entries, come values e keys.', 188 | example: `let iterator = arr.entries();
189 | console.log(iterator.next().value);`, 190 | output: `[0, 5]
191 | // 0 è il primo indice,
192 | // 5 è il primo numero` 193 | } 194 | ], 195 | find: { 196 | single: [ 197 | { 198 | name: 'includes', 199 | shortDesc: 'se un certo elemento esiste', 200 | desc: 201 | 'Determina se un array contiene un certo elemento, restituendo true o false.', 202 | example: `console.log(arr.includes(1));`, 203 | output: `true` 204 | }, 205 | { 206 | name: 'indexOf', 207 | shortDesc: 'la prima posizione di un elemento', 208 | desc: 209 | 'Restituisce la prima posizione nella quale si trova un elemento uguale a quello specificato, o -1 se non è presente.', 210 | example: `console.log(arr.indexOf(5));`, 211 | output: `0` 212 | }, 213 | { 214 | name: 'lastIndexOf', 215 | shortDesc: 'l\'ultima posizione di un elemento', 216 | desc: 217 | 'Restituisce l\'ultima posizione (la maggiore) nella quale si trova un elemento uguale a quello specificato, o -1 se non è presente.', 218 | example: `console.log(arr.lastIndexOf(5));`, 219 | output: `0` 220 | }, 221 | { 222 | name: 'find', 223 | shortDesc: 'il primo elemento che soddisfa una condizione', 224 | desc: 225 | `Restituisce il primo valore dell'array che soddisfa la funzione specificata, o undefined se non ce n'è nessuno.
226 | È simile a findIndex, ma restituisce l'elemento anziché la sua posizione.`, 227 | example: `let piccolo = (el) => el < 2;
228 | console.log(arr.find(piccolo));`, 229 | output: `1` 230 | }, 231 | { 232 | name: 'findIndex', 233 | shortDesc: 'la posizione del primo elemento che soddisfa una condizione', 234 | desc: 235 | `Restituisce la posizione del primo valore dell'array che soddisfa la funzione specificata, o -1 se non ce n'è nessuno.
236 | È simile a find, ma restituisce la posizione di un elemento anziché il suo valore.`, 237 | example: `let grande = (el) => el > 6;
238 | console.log(arr.findIndex(grande));`, 239 | output: `2` 240 | }, 241 | { 242 | name: 'reduce', 243 | shortDesc: 'un valore a cui ridurre l\'array, dall\'inizio alla fine', 244 | desc: 245 | 'Richiama una funzione con un accumulatore e ogni valore dell\'array, da sinistra a destra, per ridurlo a un singolo valore.', 246 | example: `let somma = (a, b) => a + b;
247 | console.log(arr.reduce(somma));`, 248 | output: `14` 249 | }, 250 | { 251 | name: 'reduceRight', 252 | shortDesc: 'un valore a cui ridurre l\'array, dalla fine all\'inizio', 253 | desc: 254 | 'Richiama una funzione con un accumulatore e ogni valore dell\'array, da destra a sinistra, per ridurlo a un singolo valore.', 255 | example: `[arr, [0, 1]].reduceRight((a, b) => {
256 |   return a.concat(b)
257 | }, [])`, 258 | output: `[0, 1, 5, 1, 8]` 259 | } 260 | ], 261 | many: [ 262 | { 263 | name: 'filter', 264 | shortDesc: 'i valori che rispettano una condizione specificata', 265 | desc: 266 | 'Crea un nuovo array con tutti gli elementi dell\'array originale per i quali la funzione di filtro specificata restituisce true.', 267 | example: `let filtrato = arr.filter(el => el > 4);
268 | console.log(filtrato)`, 269 | output: `[5, 8]` 270 | }, 271 | { 272 | name: 'every', 273 | shortDesc: 'se ogni elemento soddisfa una condizione', 274 | desc: 275 | 'Restituisce true se ogni elemento in questo array soddisfa il test della funzione specificata.', 276 | example: `let minoreDi10 = (el) => el < 10;
277 | console.log(arr.every(minoreDi10));`, 278 | output: `true` 279 | }, 280 | { 281 | name: 'some', 282 | shortDesc: 'se almeno un elemento soddisfa una condizione', 283 | desc: 284 | 'Restituisce true se almeno un elemeto in questo array soddisfa il test della funzione specificata.', 285 | example: `let maggioreDi4 = (el) => el > 4;
286 | console.log(arr.some(maggioreDi4));`, 287 | output: `true` 288 | } 289 | ] 290 | } 291 | } 292 | } 293 | -------------------------------------------------------------------------------- /src/store/nl.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: 'element/en aan een array', 8 | desc: 'Voegt een element toe aan een array of verwijderd een element van een array.', 9 | example: `arr.splice(2, 0, 'tacos');
10 | console.log(arr);`, 11 | output: `[5, 1, 'tacos', 8]` 12 | }, 13 | { 14 | name: 'push', 15 | shortDesc: 'element aan het einde van een array', 16 | desc: 'Voegt een of meerdere elementen toe aan het einde van een array en geeft de nieuwe lengte van de array terug.', 17 | example: `arr.push(2);
18 | console.log(arr);`, 19 | output: '[5, 1, 8, 2]' 20 | }, 21 | { 22 | name: 'unshift', 23 | shortDesc: 'element aan het begin van een array', 24 | desc: 'Voegt een of meerdere elementen toe aan het begin van een array en geeft de nieuwe lengte van de array terug.', 25 | example: `arr.unshift(2, 7);
26 | console.log(arr);`, 27 | output: '[2, 7, 5, 1, 8]' 28 | }, 29 | { 30 | name: 'concat', 31 | shortDesc: 'deze array aan (een) andere array(s) en/of waarde(s)', 32 | desc: 'Geeft een nieuwe array terug bestaande uit deze array samengevoegd met andere array(s) en/of waarde(s).', 33 | example: `let arr2 = ['a', 'b', 'c'];
34 | let arr3 = arr.concat(arr2);
35 | console.log(arr3);`, 36 | output: `[5, 1, 8, 'a', 'b', 'c']` 37 | } 38 | ], 39 | removing: [ 40 | { 41 | name: 'splice', 42 | shortDesc: 'element/en van een array', 43 | desc: 'Voegt een element toe aan een array of verwijderd een element van een array.', 44 | example: `arr.splice(2, 1);
45 | console.log(arr);`, 46 | output: `[5, 1]` 47 | }, 48 | { 49 | name: 'pop', 50 | shortDesc: 'laatste element van een array', 51 | desc: 52 | 'Verwijderd het laatste element van een array en geeft dat element terug.', 53 | example: `arr.pop();
54 | console.log(arr);`, 55 | output: `[5, 1]` 56 | }, 57 | { 58 | name: 'shift', 59 | shortDesc: 'the first element of the array', 60 | shortDesc: 'het eerste element van een array', 61 | desc: 62 | 'Verwijderd het eerste element van een array and geeft dat element terug.', 63 | example: `arr.shift();
64 | console.log(arr);`, 65 | output: `[1, 8]` 66 | }, 67 | { 68 | name: 'slice', 69 | shortDesc: 'een of meerdere elementen in de huidige volgorde, zonder dat de array wordt aangepast,', 70 | desc: 71 | 'De slice() methode geeft een kopie van een gedeelte van de array terug in een nieuwe array. Je kan kiezen voor het beginnende element (waar het einde standaard gelijk is aan de lengte van de array) opgeven of zowel het begin als einde opgeven, gescheiden met een komma. De orginele array wordt niet aangepast.', 72 | example: `let slicedArr = arr.slice(1);
73 | console.log(arr);
74 | console.log(slicedArr);`, 75 | output: `[5, 1, 8]
76 | [1, 8]` 77 | } 78 | ], 79 | string: [ 80 | { 81 | name: 'join', 82 | shortDesc: 'alle elementen van een array samenvoegen als string', 83 | desc: 84 | `Voegt alle elementen van een array samen tot een string. Je kan het samenvoegen zoals het is of met iets er tussen, elements.join(' - ') gives you foo-bar.`, 85 | example: `console.log(arr.join());`, 86 | output: `"5,1,8"` 87 | }, 88 | { 89 | name: 'toString', 90 | shortDesc: 'een array weergeven als string', 91 | desc: 'Geeft de array en de elementen daarvan weer als string.', 92 | example: `console.log(arr.toString());`, 93 | output: `"5,1,8"` 94 | }, 95 | { 96 | name: 'toLocaleString', 97 | shortDesc: 'return a localized string representing the array.', 98 | shortDesc: 'een array weergeven als taal string', 99 | desc: 100 | 'Dit is een gekke. Deze functie geeft de array en de elementen daarvan weer als een taal string. Dit kan heel nuttig zijn voor datums en valuta en heeft wat vreemde abstracties, dus het beste is om de documentatie te raadplegen wanneer je deze functie gebruikt.', 101 | example: `let date = [new Date()];
102 | const arrString = arr.toLocaleString();
103 | const dateString = date.toLocaleString();
104 | console.log(arrString, dateString);`, 105 | output: `"5,1,8 12/26/2017, 6:54:49 PM"` 106 | } 107 | ], 108 | ordering: [ 109 | { 110 | name: 'reverse', 111 | shortDesc: 'de volgorde van een array omkeren', 112 | desc: 113 | 'Keert de volgorde van de elementen in een array om waar het eerste element het laatste element wordt en vice versa.', 114 | example: `arr.reverse();
115 | console.log(arr);`, 116 | output: `[8, 1, 5]` 117 | }, 118 | { 119 | name: 'sort', 120 | shortDesc: 'elementen van een array sorteren', 121 | desc: 'Sorteert de elementen van een array en geeft de array vervolgens terug.', 122 | desc: `Sorts the elements of an array in place and returns the array.
123 |
124 | Belangrijke opmerking: Als de compareFunction niet is toegepast, dan worden elementen gesorteerd door middel van conversie naar strings en worden deze vergeleken in Unicode code point volgorde. Bijvoorbeeld, "Banaan" komt voor "kers". In nummeriek volgorde, komt 9 voor 80, maar omdat nummers geconverteerd worden naar strings, komt "80" voor "9" in Unicode order. De documentatie heeft meer informatie om het te verduidelijken.`, 125 | example: `arr.sort();
126 | console.log(arr);`, 127 | output: `[1, 5, 8]` 128 | } 129 | ], 130 | other: [ 131 | { 132 | name: 'length', 133 | shortDesc: 'de lengte van een array vinden', 134 | desc: 'Geeft het aantal elementen in een array terug.', 135 | example: `console.log(arr.length);`, 136 | output: `3` 137 | }, 138 | { 139 | name: 'fill', 140 | shortDesc: 'Alle elementen van een array vullen met een statische waarde', 141 | desc: 142 | 'Vult alle elementen van een array met een statische waarde.', 143 | example: `arr.fill(2);
144 | console.log(arr);`, 145 | output: `[2, 2, 2]` 146 | }, 147 | { 148 | name: 'copyWithin', 149 | shortDesc: 'een kopie van de volgorde van array elementen maken binnen de array', 150 | desc: 151 | 'Maakt een kopie van de volgorde van array elementen binnen de array. Je kan er voor kiezen om het eind element te kiezen (Waar het begin standaard 0 is) of zowel begin tot eind te kiezen, met een komma gescheiden. ', 152 | example: `arr.copyWithin(1);
153 | console.log(arr);`, 154 | output: `[5, 5, 1]` 155 | } 156 | ], 157 | iterate: [ 158 | { 159 | name: 'forEach', 160 | shortDesc: 'een functie uit te voeren voor elk element', 161 | desc: 162 | 'De forEach() methode voert eenmalig een functie uit voor elk element in de array.', 163 | example: `arr.forEach((element) => {
164 |   console.log(element)
165 | });`, 166 | output: `5
167 | 1
168 | 8` 169 | }, 170 | { 171 | name: 'map', 172 | shortDesc: 173 | 'een nieuwe array te maken van elk element met een functie die uitgevoerd wordt', 174 | desc: 175 | 'Maakt een nieuwe array aan met het resultaat van de uitgevoerde functie van elk element in de array.', 176 | example: `let map = arr.map(x => x + 1);
177 | console.log(map);`, 178 | output: `[6, 2, 9]` 179 | }, 180 | { 181 | name: 'entries', 182 | shortDesc: 'een iteratie object aan te maken', 183 | desc: 184 | 'Geeft een nieuw array iteratie object terug dat de sleutel/waarde koppelt voor elke index in de array. Er is veel mogelijk met intereren, in samenwerking met andere methodes, zoals ook values en keys.', 185 | example: `let iterator = arr.entries();
186 | console.log(iterator.next().value);`, 187 | output: `[0, 5]
188 | // the 0 is the index,
189 | // the 5 is the first number` 190 | } 191 | ], 192 | find: { 193 | single: [ 194 | { 195 | name: 'includes', 196 | shortDesc: 'of een element bestaat in de array', 197 | desc: 198 | 'Bepaald of een array een bepaald element bevat, en geeft vervolgens true of false terug voor de uitkomst.', 199 | example: `console.log(arr.includes(1));`, 200 | output: `true` 201 | }, 202 | { 203 | name: 'indexOf', 204 | shortDesc: 'de eerste index van een bepaald element', 205 | desc: 206 | 'Geeft de eerst komende index terug van het gegeven element, of geeft -1 terug als het element niet gevonden kan worden.', 207 | example: `console.log(arr.indexOf(5));`, 208 | output: `0` 209 | }, 210 | { 211 | name: 'lastIndexOf', 212 | shortDesc: 'de laatste index van een bepaald element', 213 | desc: 214 | 'Geeft de laatst mogelijke index terug van het gegeven element, of geeft -1 terug als het element niet gevonden kan worden.', 215 | example: `console.log(arr.lastIndexOf(5));`, 216 | output: `0` 217 | }, 218 | { 219 | name: 'find', 220 | shortDesc: 'het eerste element dat overeenkomt met de conditie', 221 | desc: 222 | 'Geeft de waarde terug uit de array, als het element in de array overeenkomt met de conditie die aangegeven is, en geeft anders undefined terug als er geen element gevonden is. Ongeveerd hetzelfde als findIndex() maar dit geeeft de waarde van het element terug in plaats van de index.', 223 | example: `let isTiny = (el) => el < 2;
224 | console.log(arr.find(isTiny));`, 225 | output: `1` 226 | }, 227 | { 228 | name: 'findIndex', 229 | shortDesc: 'de eerste index van een element dat overeenkomt met de conditie', 230 | desc: 231 | 'Geeft de index terug van het eerste element uit de array dat overeenkomt met de conditie die aangegeven is, en anders -1 terug geeft. Ongeveer hetzelfde als find(), maar dit geeft de index terug in plaats van de waarde van het element.', 232 | example: `let isBig = (el) => el > 6;
233 | console.log(arr.findIndex(isBig));`, 234 | output: `2` 235 | }, 236 | { 237 | name: 'reduce', 238 | shortDesc: 'een waarde door het verkleinen van de array, van begin tot eind', 239 | desc: 240 | 'Pas een functie toe op een verzameling en elke waarde in de array (van links naar rechts) aan door het te verkleinen in een enkele waarde.', 241 | example: `let reducer = (a, b) => a + b;
242 | console.log(arr.reduce(reducer));`, 243 | output: `14` 244 | }, 245 | { 246 | name: 'reduceRight', 247 | shortDesc: 'een waarde door het verkleinen van de array, van eind tot begin', 248 | desc: 249 | 'Pas een functie toe op een verzameling en elke waarde in de array (van rechts naar links) door het te verkleinen in een enkele waarde.', 250 | example: `[arr, [0, 1]].reduceRight((a, b) => {
251 |   return a.concat(b)
252 | }, [])`, 253 | output: `[0, 1, 5, 1, 8]` 254 | } 255 | ], 256 | many: [ 257 | { 258 | name: 'filter', 259 | shortDesc: 'waardes gebaseerd op een conditie die ik toepas', 260 | desc: 261 | 'Maakt een nieuwe array met alle elementen van deze array waarbij de conditie overeenkomt en true terug geeft.', 262 | example: `let filtered = arr.filter(el => el > 4);
263 | console.log(filtered)`, 264 | output: `[5, 8]` 265 | }, 266 | { 267 | name: 'every', 268 | shortDesc: 'of alle waardes in een array overeenkomen met de conditie die ik stel', 269 | desc: 270 | 'Geeft true terug als elk element in de array overeenkomt met de opgegeven conditie.', 271 | example: `let isSmall = (el) => el < 10;
272 | console.log(arr.every(isSmall));`, 273 | output: `true` 274 | }, 275 | { 276 | name: 'some', 277 | shortDesc: 'of een waarde in een array overeenkomt met de conditie die ik stel', 278 | desc: 279 | 'Geeft true terug als er minimaal een element in de array overenekomt met de opgegeven conditie.', 280 | example: `let biggerThan4 = (el) => el > 4;
281 | console.log(arr.some(biggerThan4));`, 282 | output: `true` 283 | } 284 | ] 285 | } 286 | } 287 | } 288 | -------------------------------------------------------------------------------- /src/store/pt.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: 'elemento(s) no array', 8 | desc: 'Adiciona e/ou remove elementos do array.', 9 | example: `arr.splice(2, 0, 'tacos');
10 | console.log(arr);`, 11 | output: `[5, 1, 'tacos', 8]` 12 | }, 13 | { 14 | name: 'push', 15 | shortDesc: 'elementos no final do array', 16 | desc: 17 | 'Adiciona um ou mais elementos no final do array e retorna o novo tamanho do array.', 18 | example: `arr.push(2);
19 | console.log(arr);`, 20 | output: '[5, 1, 8, 2]' 21 | }, 22 | { 23 | name: 'unshift', 24 | shortDesc: 'elementos no início do array', 25 | desc: 26 | 'Adiciona um ou mais elementos no início do array e retorna o novo tamanho do array.', 27 | example: `arr.unshift(2, 7);
28 | console.log(arr);`, 29 | output: '[2, 7, 5, 1, 8]' 30 | }, 31 | { 32 | name: 'concat', 33 | shortDesc: 'este array a outro(s) array(s) e/ou valor(es)', 34 | desc: 35 | 'Retorna um novo array incluindo este array concatenado de outro(s) arrays e/ou valor(es).', 36 | example: `let arr2 = ['a', 'b', 'c'];
37 | let arr3 = arr.concat(arr2);
38 | console.log(arr3);`, 39 | output: `[5, 1, 8, 'a', 'b', 'c']` 40 | } 41 | ], 42 | removing: [ 43 | { 44 | name: 'splice', 45 | shortDesc: 'elemento(s) no array', 46 | desc: 'Adiciona e/ou remove elementos do array.', 47 | example: `arr.splice(2, 1);
48 | console.log(arr);`, 49 | output: `[5, 1]` 50 | }, 51 | { 52 | name: 'pop', 53 | shortDesc: 'o último elemento do array', 54 | desc: 'Remove o último elemento do array e retorna o elemento.', 55 | example: `arr.pop();
56 | console.log(arr);`, 57 | output: `[5, 1]` 58 | }, 59 | { 60 | name: 'shift', 61 | shortDesc: 'o primeiro elemento do array', 62 | desc: 'Remove o primeiro elemento do array e retorna o elemento.', 63 | example: `arr.shift();
64 | console.log(arr);`, 65 | output: `[1, 8]` 66 | }, 67 | { 68 | name: 'slice', 69 | shortDesc: 70 | 'um ou mais elementos, mantendo o array original sem alterações', 71 | desc: 72 | 'O método slice() retorna uma cópia rasa de parte do array em um novo objeto array. Você pode especificar apenas o índice final (deixando o índice inicial assumir o valor padrão zero), ou ambos, o índice inicial e o índice final separados por vírgula. O array original não será modificado.', 73 | example: `let slicedArr = arr.slice(1);
74 | console.log(arr);
75 | console.log(slicedArr);`, 76 | output: `[5, 1, 8]
77 | [1, 8]` 78 | } 79 | ], 80 | string: [ 81 | { 82 | name: 'join', 83 | shortDesc: 'unir todos os elementos do array em uma string.', 84 | desc: `Une todos elementos do array em uma string. Você pode unir todos os itens sem delimitadores, ou com algum delimitador entre os elementos, elements.join(' - 85 | ') retorna foo-bar`, 86 | example: `console.log(arr.join());`, 87 | output: `"5,1,8"` 88 | }, 89 | { 90 | name: 'toString', 91 | shortDesc: 'retornar uma string representando o array.', 92 | desc: 'Retorna uma string representando um array e seus elementos.', 93 | example: `console.log(arr.toString());`, 94 | output: `"5,1,8"` 95 | }, 96 | { 97 | name: 'toLocaleString', 98 | shortDesc: 'retornar uma string localizada representando o array.', 99 | desc: 100 | 'Retorna uma string localizada representando um array e seus elementos. É muito útil para datas e moedas com características específicas do locale, recomendo consultar a documentação quando utilizar esta função.', 101 | example: `let date = [new Date()];
102 | const arrString = arr.toLocaleString();
103 | const dateString = date.toLocaleString();
104 | console.log(arrString, dateString);`, 105 | output: `"5,1,8 12/26/2017, 6:54:49 PM"` 106 | } 107 | ], 108 | ordering: [ 109 | { 110 | name: 'reverse', 111 | shortDesc: 'inverter a ordem do array', 112 | desc: 113 | 'Inverte a ordem dos elementos do array modificando o array — o primeiro elemento se torna o último, e o último se torna o primeiro.', 114 | example: `arr.reverse();
115 | console.log(arr);`, 116 | output: `[8, 1, 5]` 117 | }, 118 | { 119 | name: 'sort', 120 | shortDesc: 'ordenar os itens do array', 121 | desc: 122 | 'Orderna os itens do array modificando o array e retorna o próprio array.', 123 | example: `arr.sort();
124 | console.log(arr);`, 125 | output: `[1, 5, 8]` 126 | } 127 | ], 128 | other: [ 129 | { 130 | name: 'length', 131 | shortDesc: 'retornar o comprimento do array', 132 | desc: 'Retorna o número de elementos existentes no array.', 133 | example: `console.log(arr.length);`, 134 | output: `3` 135 | }, 136 | { 137 | name: 'fill', 138 | shortDesc: 139 | 'preencher todos os elementos do array com um valor estático', 140 | desc: 141 | 'Preenche todos os elementos do array de um índice inicial até um índice final com valores estáticos.', 142 | example: `arr.fill(2);
143 | console.log(arr);`, 144 | output: `[2, 2, 2]` 145 | }, 146 | { 147 | name: 'copyWithin', 148 | shortDesc: 'copiar parte do array dentro do mesmo array.', 149 | desc: 150 | 'Copia parte do array para outra localização dentro deste mesmo array e o retorna, sem alterar seu tamanho. Você pode especificar o índice final (deixando o índice inicial assumir o valor padrão zero), ou ambos, o índice inicial e o índice final separados por vírgula', 151 | example: `arr.copyWithin(1);
152 | console.log(arr);`, 153 | output: `[5, 5, 1]` 154 | } 155 | ], 156 | iterate: [ 157 | { 158 | name: 'forEach', 159 | shortDesc: 'executando uma função sobre cada elemento', 160 | desc: 161 | 'O método forEach() executa uma função fornecida como parâmetro para cada elemento do array.', 162 | example: `arr.forEach((element) => {
163 |   console.log(element)
164 | });`, 165 | output: `5
166 | 1
167 | 8` 168 | }, 169 | { 170 | name: 'map', 171 | shortDesc: 172 | 'criando um novo array a partir de cada elemento transformado via uma função', 173 | desc: 174 | 'Cria um novo array com o resultado da chamada da função para cada elemento no array.', 175 | example: `let map = arr.map(x => x + 1);
176 | console.log(map);`, 177 | output: `[6, 2, 9]` 178 | }, 179 | { 180 | name: 'entries', 181 | shortDesc: 'criando um objeto iterator', 182 | desc: 183 | 'Retorna um novo objeto do tipo Array Iterator que contém pares de chave/valor para cada índice do array. Há diversos usos para iterators, assim como há outros métodos análogos, como o método values e o método keys', 184 | example: `let iterator = arr.entries();
185 | console.log(iterator.next().value);`, 186 | output: `[0, 5]
187 | // o 0 é o índice,
188 | // o 5 é o primeiro número` 189 | } 190 | ], 191 | find: { 192 | single: [ 193 | { 194 | name: 'includes', 195 | shortDesc: 'se um dado elemento existe', 196 | desc: 197 | 'Verifica se um array contém um certo elemento, retornando true ou false.', 198 | example: `console.log(arr.includes(1));`, 199 | output: `true` 200 | }, 201 | { 202 | name: 'indexOf', 203 | shortDesc: 'o primeiro índice de um elemento', 204 | desc: 205 | 'Retorna o primeiro índice no qual um dado elemento pode ser encontrado no array, ou retorna -1 se não existe o item.', 206 | example: `console.log(arr.indexOf(5));`, 207 | output: `0` 208 | }, 209 | { 210 | name: 'lastIndexOf', 211 | shortDesc: 'o último índice de um elemento', 212 | desc: 213 | 'Retorna o último (maior) índice no qual um dado elemento pode ser encontrado no array, ou retorna -1 se não existe o item.', 214 | example: `console.log(arr.lastIndexOf(5));`, 215 | output: `0` 216 | }, 217 | { 218 | name: 'find', 219 | shortDesc: 'o primeiro elemento que satisfaz a condição', 220 | desc: 221 | 'Retorna o valor econtrado no array, se um elemento no array satisfaz o teste da função fornecida como parâmetro, ou retorna undefined se não encontrado. Similar ao método findIndex(), porém esta função retorna o item ao invés do índice.', 222 | example: `let isTiny = (el) => el < 2;
223 | console.log(arr.find(isTiny));`, 224 | output: `1` 225 | }, 226 | { 227 | name: 'findIndex', 228 | shortDesc: 'o primeiro índice de um elemento que satisfaz a condição', 229 | desc: 230 | 'Retorna o índice do primeiro elemento no array que satisfaz o teste da função fornecida como parâmetro. Senão, o valor -1 é retornado. Similar ao método find(), porém esta função retorna o índice ao invés do item.', 231 | example: `let isBig = (el) => el > 6;
232 | console.log(arr.findIndex(isBig));`, 233 | output: `2` 234 | }, 235 | { 236 | name: 'reduce', 237 | shortDesc: 'um valor através da redução do array, início ao fim', 238 | desc: 239 | 'Aplica uma função sobre um acumulador e cada elemento do array (da esquerda para direita) até reduzir a um único valor.', 240 | example: `let reducer = (a, b) => a + b;
241 | console.log(arr.reduce(reducer));`, 242 | output: `14` 243 | }, 244 | { 245 | name: 'reduceRight', 246 | shortDesc: 'um valor através da redução do array, fim ao ínicio', 247 | desc: 248 | 'Aplica uma função sobre um acumulador e cada elemento do array (da direta para esquerda) até reduzir a um único valor.', 249 | example: `[arr, [0, 1]].reduceRight((a, b) => {
250 |   return a.concat(b)
251 | }, [])`, 252 | output: `[0, 1, 5, 1, 8]` 253 | } 254 | ], 255 | many: [ 256 | { 257 | name: 'filter', 258 | shortDesc: 'um valor baseado numa condição que eu criei', 259 | desc: 260 | 'Cria um novo array com todos os elementos do array que satisfazem o teste da função fornecida como parâmetro.', 261 | example: `let filtered = arr.filter(el => el > 4);
262 | console.log(filtered)`, 263 | output: `[5, 8]` 264 | }, 265 | { 266 | name: 'every', 267 | shortDesc: 'se todos elementos satisfazem uma condição', 268 | desc: 269 | 'Retorna true se todos elementos no array satisfazem o teste da função fornecida como parâmetro.', 270 | example: `let isSmall = (el) => el < 10;
271 | console.log(arr.every(isSmall));`, 272 | output: `true` 273 | }, 274 | { 275 | name: 'some', 276 | shortDesc: 'se pelo menos algum elemento satisfaz uma condição', 277 | desc: 278 | 'Retorna true se pelo menos um elemento no array satisfaz o teste da função fornecida como parâmetro.', 279 | example: `let biggerThan4 = (el) => el > 4;
280 | console.log(arr.some(biggerThan4));`, 281 | output: `true` 282 | } 283 | ] 284 | } 285 | } 286 | } 287 | -------------------------------------------------------------------------------- /src/store/ru.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: 'элемент(ы) в массив', 8 | desc: 'Добавляет и/или удаляет элементы из массива.', 9 | example: `arr.splice(2, 0, 'tacos');
10 | console.log(arr);`, 11 | output: `[5, 1, 'tacos', 8]` 12 | }, 13 | { 14 | name: 'push', 15 | shortDesc: 'элемент(ы) в конец массива', 16 | desc: 17 | 'Добавляет один или более элементов в конец массива и возвращает новую длину этого массива.', 18 | example: `arr.push(2);
19 | console.log(arr);`, 20 | output: '[5, 1, 8, 2]' 21 | }, 22 | { 23 | name: 'unshift', 24 | shortDesc: 'элемент(ы) в начало массива', 25 | desc: 26 | 'Добавляет один или более элементов в начало массива и возвращает длину этого массива.', 27 | example: `arr.unshift(2, 7);
28 | console.log(arr);`, 29 | output: '[2, 7, 5, 1, 8]' 30 | }, 31 | { 32 | name: 'concat', 33 | shortDesc: 'этот массив к другим массивам и/или значениям', 34 | desc: 35 | 'Возвращает новый массив, составленный из этого массива и других массивов и/или значений.', 36 | example: `let arr2 = ['a', 'b', 'c'];
37 | let arr3 = arr.concat(arr2);
38 | console.log(arr3);`, 39 | output: `[5, 1, 8, 'a', 'b', 'c']` 40 | } 41 | ], 42 | removing: [ 43 | { 44 | name: 'splice', 45 | shortDesc: 'элементы из массива', 46 | desc: 'Добавляет и/или удаляет элементы из массива.', 47 | example: `arr.splice(2, 1);
48 | console.log(arr);`, 49 | output: `[5, 1]` 50 | }, 51 | { 52 | name: 'pop', 53 | shortDesc: 'последний элемент массива', 54 | desc: 55 | 'Удаляет последний элемент из массива и возвращает удалённый элемент.', 56 | example: `arr.pop();
57 | console.log(arr);`, 58 | output: `[5, 1]` 59 | }, 60 | { 61 | name: 'shift', 62 | shortDesc: 'первый элемент массива', 63 | desc: 64 | 'Удаляет первый элемент из массива и возвращает удалённый элемент.', 65 | example: `arr.shift();
66 | console.log(arr);`, 67 | output: `[1, 8]` 68 | }, 69 | { 70 | name: 'slice', 71 | shortDesc: 72 | 'один или более элементов для использования, оставив массив неизменённым', 73 | desc: 74 | 'Метод slice() возвращает поверхностную копию части массива как новый объект массива. Вы можете определить только начальный элемент (тогда концом будет взята длина массива) либо и начальный, и конечный элемент, разделённые запятой. Изначальный массив не будет изменён.', 75 | example: `let slicedArr = arr.slice(1);
76 | console.log(arr);
77 | console.log(slicedArr);`, 78 | output: `[5, 1, 8]
79 | [1, 8]` 80 | } 81 | ], 82 | string: [ 83 | { 84 | name: 'join', 85 | shortDesc: 'объединить все элементы массива в строку', 86 | desc: `Объединяет все элементы в строку. Вы можете объединить элементы по умолчанию или использовать разделитель, elements.join(' - ') вернёт foo-bar`, 87 | example: `console.log(arr.join());`, 88 | output: `"5,1,8"` 89 | }, 90 | { 91 | name: 'toString', 92 | shortDesc: 'вернуть строку представляющую массив', 93 | desc: 'Возвращает строку представляющую массив и его элементы.', 94 | example: `console.log(arr.toString());`, 95 | output: `"5,1,8"` 96 | }, 97 | { 98 | name: 'toLocaleString', 99 | shortDesc: 'вернуть локализованную строку представлющую массив', 100 | desc: 101 | 'Этот метод немного странный. Возвращает локализованную строку представлющую массив и его элементы. Это очень удобно для дат и денежных единиц, а также имеет некоторые необычные национальные абстракции, поэтому лучше обратиться к документации перед использованием.', example: `let date = [new Date()];
102 | const arrString = arr.toLocaleString();
103 | const dateString = date.toLocaleString();
104 | console.log(arrString, dateString);`, 105 | output: `"5,1,8 12/26/2017, 6:54:49 PM"` 106 | } 107 | ], 108 | ordering: [ 109 | { 110 | name: 'reverse', 111 | shortDesc: 'обратить порядок элементов массива', 112 | desc: 113 | 'Обращает порядок элементов массива на месте — первый становится последним, а последний становится первым.', 114 | example: `arr.reverse();
115 | console.log(arr);`, 116 | output: `[8, 1, 5]` 117 | }, 118 | { 119 | name: 'sort', 120 | shortDesc: 'отсортировать элементы массива', 121 | desc: `Сортирует элементы массива на месте и возвращает этот массив.
122 |
123 | Важное замечание: Если compareFunction не определена, элементы будут отсортированы с предварительным приведением их к строковому типу в кодировке Unicode. Например, "Banana" будет идти до "cherry". При сортировке чисел, 9 идёт до 80, но поскольку числа конвертируются в строки, "80" идёт до "9" в порядке символов Unicode. В документации можно найти больше поясняющей информации.`, 124 | example: `arr.sort();
125 | console.log(arr);`, 126 | output: `[1, 5, 8]` 127 | } 128 | ], 129 | other: [ 130 | { 131 | name: 'length', 132 | shortDesc: 'найти длину массива', 133 | desc: 'Возвращает количество элементов в этом массиве.', 134 | example: `console.log(arr.length);`, 135 | output: `3` 136 | }, 137 | { 138 | name: 'fill', 139 | shortDesc: 'заполнить все элементы массива статическим значением', 140 | desc: 141 | 'Заполняет все элементы массива, начиная со стартового и до конечного индекса, статическим значением', 142 | example: `arr.fill(2);
143 | console.log(arr);`, 144 | output: `[2, 2, 2]` 145 | }, 146 | { 147 | name: 'copyWithin', 148 | shortDesc: 'скопировать последовательность элементов внутри массива', 149 | desc: 150 | 'Копирует последовательность элементов внутри массива. Вы можете определить только конечный элемент (тогда началом будет взят нуль) либо и начальный, и конечный элемент, разделённые запятой.', 151 | example: `arr.copyWithin(1);
152 | console.log(arr);`, 153 | output: `[5, 5, 1]` 154 | } 155 | ], 156 | iterate: [ 157 | { 158 | name: 'forEach', 159 | shortDesc: 'выполняя функцию, которую я создам, над каждым элементом массива', 160 | desc: 161 | 'Метод forEach() выполняет переданную функцию единожды для каждого элемента массива.', 162 | example: `arr.forEach((element) => {
163 |   console.log(element)
164 | });`, 165 | output: `5
166 | 1
167 | 8` 168 | }, 169 | { 170 | name: 'map', 171 | shortDesc: 172 | 'создавая новый массив из элементов с помощью моей функции', 173 | desc: 174 | 'Создаёт новый массив используя результаты вызова переданной функции для каждого элемента в этом массиве.', 175 | example: `let map = arr.map(x => x + 1);
176 | console.log(map);`, 177 | output: `[6, 2, 9]` 178 | }, 179 | { 180 | name: 'entries', 181 | shortDesc: 'создав объект-итератор', 182 | desc: 183 | 'Возвращает новый объект-итератор для массива, который содержит пары ключ/значение для каждого индекса в этом массиве. Существует много способов использования этого итератора, а также методов, связаных с ним, таких как values и keys', 184 | example: `let iterator = arr.entries();
185 | console.log(iterator.next().value);`, 186 | output: `[0, 5]
187 | // the 0 is the index,
188 | // the 5 is the first number` 189 | } 190 | ], 191 | find: { 192 | single: [ 193 | { 194 | name: 'includes', 195 | shortDesc: 'существует ли определённый элемент', 196 | desc: 197 | 'Определяет содержит ли массив определённый элемент, возвращает true или false как полагается.', 198 | example: `console.log(arr.includes(1));`, 199 | output: `true` 200 | }, 201 | { 202 | name: 'indexOf', 203 | shortDesc: 'первый индекс определённого элемента', 204 | desc: 205 | 'Возвращает первый индекс, в котором встречается данный элемент в массиве или -1, если элемента не существует.', 206 | example: `console.log(arr.indexOf(5));`, 207 | output: `0` 208 | }, 209 | { 210 | name: 'lastIndexOf', 211 | shortDesc: 'последний индекс определённого элемента', 212 | desc: 213 | 'Возвращает последний (наибольший) индекс, в котором встречается данный элемент в массиве или -1, если элемента не существует.', 214 | example: `console.log(arr.lastIndexOf(5));`, 215 | output: `0` 216 | }, 217 | { 218 | name: 'find', 219 | shortDesc: 'первый элемент соответствующий условию', 220 | desc: 221 | 'Возвращает найденное в массиве значение, если элемент в массиве соответствует переданной тестирующей функции или undefined, если такой элемент не найден. Подобен findIndex(), но возвращает элемент вместо индекса.', 222 | example: `let isTiny = (el) => el < 2;
223 | console.log(arr.find(isTiny));`, 224 | output: `1` 225 | }, 226 | { 227 | name: 'findIndex', 228 | shortDesc: 'первый индекс элемента, соответствующего условию', 229 | desc: 230 | 'Возвращает индекс первого элемента в массиве, который соответствует переданной тестирующей функции. В ином случае возвращает -1. Подобен find(), но возвращает индекс вместо элемента.', 231 | example: `let isBig = (el) => el > 6;
232 | console.log(arr.findIndex(isBig));`, 233 | output: `2` 234 | }, 235 | { 236 | name: 'reduce', 237 | shortDesc: 'значение, полученное сокращением массива, от начала до конца', 238 | desc: 239 | 'Применить функцию к аккумулятору с каждым значением массива (слева направо), чтобы сократить его до единственного значения.', 240 | example: `let reducer = (a, b) => a + b;
241 | console.log(arr.reduce(reducer));`, 242 | output: `14` 243 | }, 244 | { 245 | name: 'reduceRight', 246 | shortDesc: 'значение, полученное сокращением массива, от конца к началу', 247 | desc: 248 | 'Применить функцию к аккумулятору с каждым значением массива (справа налево), чтобы сократить его до единственного значения.', 249 | example: `[arr, [0, 1]].reduceRight((a, b) => {
250 |   return a.concat(b)
251 | }, [])`, 252 | output: `[0, 1, 5, 1, 8]` 253 | } 254 | ], 255 | many: [ 256 | { 257 | name: 'filter', 258 | shortDesc: 'значения, основываясь на условви, которое я создам', 259 | desc: 260 | 'Создаёт новый массив со всеми элементами этого массива, для которых переданная фильтрующая функция возвращает true.', 261 | example: `let filtered = arr.filter(el => el > 4);
262 | console.log(filtered)`, 263 | output: `[5, 8]` 264 | }, 265 | { 266 | name: 'every', 267 | shortDesc: 'соответствует или нет каждый элемент условию', 268 | desc: 269 | 'Возвращает true, если каждый элемент в этом массиве соответствует переданной тестирующей функции.', 270 | example: `let isSmall = (el) => el < 10;
271 | console.log(arr.every(isSmall));`, 272 | output: `true` 273 | }, 274 | { 275 | name: 'some', 276 | shortDesc: 'соответствует или нет хотя бы один элемент условию', 277 | desc: 278 | 'Возращает true, если хотя бы один элемент в этом массиве соответствует переданной тестирующей функции', 279 | example: `let biggerThan4 = (el) => el > 4;
280 | console.log(arr.some(biggerThan4));`, 281 | output: `true` 282 | } 283 | ] 284 | } 285 | } 286 | } 287 | -------------------------------------------------------------------------------- /src/store/sr.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: 'element/elemente u niz', 8 | desc: 'Dodaje i/ili uklanja elemente iz niza.', 9 | example: `arr.splice(2, 0, 'tacos');
10 | console.log(arr);`, 11 | output: `[5, 1, 'tacos', 8]` 12 | }, 13 | { 14 | name: 'push', 15 | shortDesc: 'elemente na kraj niza', 16 | desc: 17 | 'Dodaje jedan ili više elemenata na kraj niza i vraća novu dužinu niza.', 18 | example: `arr.push(2);
19 | console.log(arr);`, 20 | output: '[5, 1, 8, 2]' 21 | }, 22 | { 23 | name: 'unshift', 24 | shortDesc: 'elemente na početak niza', 25 | desc: 26 | 'Dodaje jedan ili više elemenata na početak niza i vraća novu dužinu niza.', 27 | example: `arr.unshift(2, 7);
28 | console.log(arr);`, 29 | output: '[2, 7, 5, 1, 8]' 30 | }, 31 | { 32 | name: 'concat', 33 | shortDesc: 'ovaj niz sa drugim nizom/nizovima i/ili vrednošću/vrednostima', 34 | desc: 35 | 'Vraća novi niz koji se sastoji od ovog niza i drugog niza/nizova i/ili vrednosti.', 36 | example: `let arr2 = ['a', 'b', 'c'];
37 | let arr3 = arr.concat(arr2);
38 | console.log(arr3);`, 39 | output: `[5, 1, 8, 'a', 'b', 'c']` 40 | } 41 | ], 42 | removing: [ 43 | { 44 | name: 'splice', 45 | shortDesc: 'element/elemente iz niza', 46 | desc: 'Dodaje i/ili uklanja elemente iz niza.', 47 | example: `arr.splice(2, 1);
48 | console.log(arr);`, 49 | output: `[5, 1]` 50 | }, 51 | { 52 | name: 'pop', 53 | shortDesc: 'poslednji element niza', 54 | desc: 55 | 'Uklanja poslednji element iz niza i vraća taj element.', 56 | example: `arr.pop();
57 | console.log(arr);`, 58 | output: `[5, 1]` 59 | }, 60 | { 61 | name: 'shift', 62 | shortDesc: 'prvi element niza', 63 | desc: 64 | 'Uklanja prvi element iz niza i vraća taj element.', 65 | example: `arr.shift();
66 | console.log(arr);`, 67 | output: `[1, 8]` 68 | }, 69 | { 70 | name: 'slice', 71 | shortDesc: 72 | 'jedan ili više elemenata za upotrebu, ostavljajući niz onakvim kakav jeste', 73 | desc: 74 | 'Slice() metod vraća plitku kopiju porcije niza u novi objekat niza. Možete odrediti ili samo početni element (gde će kraj podrazumevano biti dužina niza) ili i početnu i krajnju vrednost, odvojene zarezom. Originalni niz će ostati neizmenjen.', 75 | example: `let slicedArr = arr.slice(1);
76 | console.log(arr);
77 | console.log(slicedArr);`, 78 | output: `[5, 1, 8]
79 | [1, 8]` 80 | } 81 | ], 82 | string: [ 83 | { 84 | name: 'join', 85 | shortDesc: 'pridružim sve elemente niza u jedan string.', 86 | desc: `Pridružuje sve elemente niza u jedan string. Možete ih pridružiti zajedno onakve kakvi jesi, ili sa nečim između, npr. elements.join(' - 87 | ') proizvodi foo-bar`, 88 | example: `console.log(arr.join());`, 89 | output: `"5,1,8"` 90 | }, 91 | { 92 | name: 'toString', 93 | shortDesc: 'vratim string koji predstavlja niz.', 94 | desc: 'Vraća string koji predstavlja niz i njegove elemente.', 95 | example: `console.log(arr.toString());`, 96 | output: `"5,1,8"` 97 | }, 98 | { 99 | name: 'toLocaleString', 100 | shortDesc: 'vratim lokalizovan string koji predstavlja niz.', 101 | desc: 102 | 'Ovo je pomalo čudno. Vraća lokalizovan string koji predstavlja niz i njegove vrednosti. Ovo je veoma korisno za datume i valute, i ima neke čudne prirodne apstrakcije, tako da je najbolje konsultovati dokumentaciju pri njegovom korišćenju.', 103 | example: `let date = [new Date()];
104 | const arrString = arr.toLocaleString();
105 | const dateString = date.toLocaleString();
106 | console.log(arrString, dateString);`, 107 | output: `"5,1,8 12/26/2017, 6:54:49 PM"` 108 | } 109 | ], 110 | ordering: [ 111 | { 112 | name: 'reverse', 113 | shortDesc: 'okrenem redosled niza', 114 | desc: 115 | 'Preokreće redosled elemenata datog niza — prvi element postaje zadnji, a zadnji postaje prvi.', 116 | example: `arr.reverse();
117 | console.log(arr);`, 118 | output: `[8, 1, 5]` 119 | }, 120 | { 121 | name: 'sort', 122 | shortDesc: 'sortiram elemente niza', 123 | desc: `Sortira elemente datog niza i vraća niz.
124 |
125 | Važna napomena:Ako compareFunction nije obezbeđena, elementi su sortirani konvertovanjem u stringove i poređenjem stringova u Unicode kodnom redosledu. Na primer, "Banana" dolazi pre "cherry". U numeričkom sortiranju, 9 dolazi pre 80, ali zbog toga što su brojevi konvertovani u stringove, "80" dolazi pre "9" u Unicode redosledu. Dokumentacija sadrži više informacija koje ovo pojašnjavaju.`, 126 | example: `arr.sort();
127 | console.log(arr);`, 128 | output: `[1, 5, 8]` 129 | } 130 | ], 131 | other: [ 132 | { 133 | name: 'length', 134 | shortDesc: 'pronađem dužinu niza', 135 | desc: 'Vraća broj elemenata datog niza.', 136 | example: `console.log(arr.length);`, 137 | output: `3` 138 | }, 139 | { 140 | name: 'fill', 141 | shortDesc: 'popunim sve elemente niza statičkom vrednošću', 142 | desc: 143 | 'Popunjava sve elemente niza od početnog indeksa do krajnjeg indeksa sa statičkom vrednošću.', 144 | example: `arr.fill(2);
145 | console.log(arr);`, 146 | output: `[2, 2, 2]` 147 | }, 148 | { 149 | name: 'copyWithin', 150 | shortDesc: 'kopiram sekvencu elemenata nizu unutar niza.', 151 | desc: 152 | 'Kopira sekvencu elemenata niza unutar niza. Možete odrediti ili krajnji element (gde će početak podrazumevano biti nula) ili i početnu i krajnju vrednost, odvojene zarezom.', 153 | example: `arr.copyWithin(1);
154 | console.log(arr);`, 155 | output: `[5, 5, 1]` 156 | } 157 | ], 158 | iterate: [ 159 | { 160 | name: 'forEach', 161 | shortDesc: 'izvršavanju funkcije koju ću da kreiram za svaki element', 162 | desc: 163 | 'forEach() metod izvršava datu funkciju nad svakim elementom niza jedanput.', 164 | example: `arr.forEach((element) => {
165 |   console.log(element)
166 | });`, 167 | output: `5
168 | 1
169 | 8` 170 | }, 171 | { 172 | name: 'map', 173 | shortDesc: 174 | 'kreiranju novog niza od svakog elementa sa funkcijom koju kreiram', 175 | desc: 176 | 'Kreira novi niz sa rezultatima pozvane funkcije nad svakim elementom u ovom nizu.', 177 | example: `let map = arr.map(x => x + 1);
178 | console.log(map);`, 179 | output: `[6, 2, 9]` 180 | }, 181 | { 182 | name: 'entries', 183 | shortDesc: 'kreiranjem iterator objekta', 184 | desc: 185 | 'Vraća novi Array Iterrator objekat koji sadrži key/value parove za svaki indeks u nizu. Postoji dosta upotreba iteratora, kao i drugih metoda u sprezi sa njima, kao npr. values i keys', 186 | example: `let iterator = arr.entries();
187 | console.log(iterator.next().value);`, 188 | output: `[0, 5]
189 | // the 0 is the index,
190 | // the 5 is the first number` 191 | } 192 | ], 193 | find: { 194 | single: [ 195 | { 196 | name: 'includes', 197 | shortDesc: 'ako postoji određeni element', 198 | desc: 199 | 'Ustanovljava da li niz sadrži određeni element, vraćajuću true ili false vrednosti.', 200 | example: `console.log(arr.includes(1));`, 201 | output: `true` 202 | }, 203 | { 204 | name: 'indexOf', 205 | shortDesc: 'prvi indeks određenog elementa', 206 | desc: 207 | 'Vraća prvi indeks na kom se dati element može pronaći u nizu, ili -1 ako on nije prisutan.', 208 | example: `console.log(arr.indexOf(5));`, 209 | output: `0` 210 | }, 211 | { 212 | name: 'lastIndexOf', 213 | shortDesc: 'zadnji indeks određenog elementa', 214 | desc: 215 | 'Vraća zadnji (najveći) indeks određenog elementa u nizu koji je jednak određenoj vrednosti, ili -1 ako nijedan nije pronađen.', 216 | example: `console.log(arr.lastIndexOf(5));`, 217 | output: `0` 218 | }, 219 | { 220 | name: 'find', 221 | shortDesc: 'prvi element koji zadovoljava određen uslov', 222 | desc: 223 | 'Vraća pronađenu vrednost unutar niza, ako element u nizu zadovoljava datu test funkciju ili undefined ako nije pronađen. Slično kao findIndex(), s tim što vraća vrednost umesto indeks.', 224 | example: `let isTiny = (el) => el < 2;
225 | console.log(arr.find(isTiny));`, 226 | output: `1` 227 | }, 228 | { 229 | name: 'findIndex', 230 | shortDesc: 'prvi indeks elementa koji zadovoljava određen uslov', 231 | desc: 232 | 'Vraća indeks prvog elementa u nizu koji zadovoljava datu test funkciju. U suprotnom vraća -1. Slično kao find(), s tim što vraća indeks umesto vrednosti.', 233 | example: `let isBig = (el) => el > 6;
234 | console.log(arr.findIndex(isBig));`, 235 | output: `2` 236 | }, 237 | { 238 | name: 'reduce', 239 | shortDesc: 'vrednost redukujući niz, od početka do kraja', 240 | desc: 241 | 'Primenjuje funkciju na akumulator i svaku vrednost niza (sa leva na desno) kako bi je smanjio na jednu vrednost.', 242 | example: `let reducer = (a, b) => a + b;
243 | console.log(arr.reduce(reducer));`, 244 | output: `14` 245 | }, 246 | { 247 | name: 'reduceRight', 248 | shortDesc: 'vrednost redukujući niz, od kraja do početka', 249 | desc: 250 | 'Primenjuje funkciju na akumulator i svaku vrednost niza (sa desna na levo) kako bi je smanjio na jednu vrednost.', 251 | example: `[arr, [0, 1]].reduceRight((a, b) => {
252 |   return a.concat(b)
253 | }, [])`, 254 | output: `[0, 1, 5, 1, 8]` 255 | } 256 | ], 257 | many: [ 258 | { 259 | name: 'filter', 260 | shortDesc: 'vrednosti na osnovu uslova koji ja zadam', 261 | desc: 262 | 'Kreira novi niz sa svim elementima ovog niza za koji data filter funkcija vraća true.', 263 | example: `let filtered = arr.filter(el => el > 4);
264 | console.log(filtered)`, 265 | output: `[5, 8]` 266 | }, 267 | { 268 | name: 'every', 269 | shortDesc: 'da li svaki element zadovoljava određen uslov ili ne', 270 | desc: 271 | 'Vraća true ako svaki element u ovom nizu zadovoljava datu test funkciju', 272 | example: `let isSmall = (el) => el < 10;
273 | console.log(arr.every(isSmall));`, 274 | output: `true` 275 | }, 276 | { 277 | name: 'some', 278 | shortDesc: 'da li barem jedan element zadovoljava određen uslov ili ne', 279 | desc: 280 | 'Vraća true ako barem jedan element u ovom nizu zadovoljava datu test funkciju', 281 | example: `let biggerThan4 = (el) => el > 4;
282 | console.log(arr.some(biggerThan4));`, 283 | output: `true` 284 | } 285 | ] 286 | } 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /src/store/ua.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: 'елемент(и) до масиву', 8 | desc: 'Додає і/або видаляє елементи з масиву.', 9 | example: `arr.splice(2, 0, 'tacos');
10 | console.log(arr);`, 11 | output: `[5, 1, 'tacos', 8]` 12 | }, 13 | { 14 | name: 'push', 15 | shortDesc: 'елемент(и) у кінець масиву', 16 | desc: 17 | 'Додає один чи більше елементів у кінець масиву и повертає новую довжину цього масиву.', 18 | example: `arr.push(2);
19 | console.log(arr);`, 20 | output: '[5, 1, 8, 2]' 21 | }, 22 | { 23 | name: 'unshift', 24 | shortDesc: 'елемент(и) на початок масиву', 25 | desc: 26 | 'Додає один чи більше елементів на початок масиву и повертає новую довжину цього масиву.', 27 | example: `arr.unshift(2, 7);
28 | console.log(arr);`, 29 | output: '[2, 7, 5, 1, 8]' 30 | }, 31 | { 32 | name: 'concat', 33 | shortDesc: 'цей масив до інших масивів і/чи значень', 34 | desc: 35 | 'Повертає новий масив, створений із цього масиву та інших масивів і/чи значень.', 36 | example: `let arr2 = ['a', 'b', 'c'];
37 | let arr3 = arr.concat(arr2);
38 | console.log(arr3);`, 39 | output: `[5, 1, 8, 'a', 'b', 'c']` 40 | } 41 | ], 42 | removing: [ 43 | { 44 | name: 'splice', 45 | shortDesc: 'елемент(и) із масиву', 46 | desc: 'Додає і/або видаляє елементи з масиву.', 47 | example: `arr.splice(2, 1);
48 | console.log(arr);`, 49 | output: `[5, 1]` 50 | }, 51 | { 52 | name: 'pop', 53 | shortDesc: 'останній елемент масиву', 54 | desc: 55 | 'Видаляє останній елемент масиву та повертає його значення.', 56 | example: `arr.pop();
57 | console.log(arr);`, 58 | output: `[5, 1]` 59 | }, 60 | { 61 | name: 'shift', 62 | shortDesc: 'перший елемент масиву', 63 | desc: 64 | 'Видаляє перший елемент масиву та повертає його значення.', 65 | example: `arr.shift();
66 | console.log(arr);`, 67 | output: `[1, 8]` 68 | }, 69 | { 70 | name: 'slice', 71 | shortDesc: 72 | 'один чи більше елементів для використання, залишивши масив незмінним', 73 | desc: 74 | 'Метод slice() повертає поверхневу копію масиву як новий обʼєкт масиву. Ви можете визначити лише початковий елемент (де кінець буде приймати значення з довжини масиву) або початок і кінець, розділені комою. Початковий масив залишиться без змін.', 75 | example: `let slicedArr = arr.slice(1);
76 | console.log(arr);
77 | console.log(slicedArr);`, 78 | output: `[5, 1, 8]
79 | [1, 8]` 80 | } 81 | ], 82 | string: [ 83 | { 84 | name: 'join', 85 | shortDesc: 'обʼєднати всі елементи масиву в стрічку', 86 | desc: `Об'єднує всі елементи масиву в стрічку. Ви можете об'єднати елементи за умовчуванням або використати розділовий знак, elements.join(' - 87 | ') повертає foo-bar`, 88 | example: `console.log(arr.join());`, 89 | output: `"5,1,8"` 90 | }, 91 | { 92 | name: 'toString', 93 | shortDesc: 'повернути рядок, що представляє масив.', 94 | desc: 'Повертає рядок, що представляє масив та його елементи.', 95 | example: `console.log(arr.toString());`, 96 | output: `"5,1,8"` 97 | }, 98 | { 99 | name: 'toLocaleString', 100 | shortDesc: 'повернути локалізований рядок, що представляє масив.', 101 | desc: 102 | 'Цей метод трохи дивний. Повертає локалізований рядок що представляє масив і його елементи. Це дуже зручно для дат і грошових одиниць, а також має деякі незвичайні національні абстракції, тому краще звернутися до документації перед використанням. ', 103 | example: `let date = [new Date()];
104 | const arrString = arr.toLocaleString();
105 | const dateString = date.toLocaleString();
106 | console.log(arrString, dateString);`, 107 | output: `"5,1,8 12/26/2017, 6:54:49 PM"` 108 | } 109 | ], 110 | ordering: [ 111 | { 112 | name: 'reverse', 113 | shortDesc: 'інвертувати порядок елементів в масиві', 114 | desc: 115 | 'Змінює порядок елементів масиву на місці - перший стає останнім, а останній стає першим.', 116 | example: `arr.reverse();
117 | console.log(arr);`, 118 | output: `[8, 1, 5]` 119 | }, 120 | { 121 | name: 'sort', 122 | shortDesc: 'сортувати елементи масиву', 123 | desc: `Сортує елементи масиву і повертає масив.
124 |
125 | Важлива примітка: Якщо compareFunction не вказано, елементи сортуються шляхом перетворення їх у рядки та порівняння рядків у порядку кодів Unicode. Наприклад, "банан" стане перед "вишні". У числовому стилі значення 9 стане до 80, але, оскільки числа перетворені в рядки, по "Порядку Юнікоду" "80" стане до "9". Документація має більше інформації для уточнення. `, 126 | example: `arr.sort();
127 | console.log(arr);`, 128 | output: `[1, 5, 8]` 129 | } 130 | ], 131 | other: [ 132 | { 133 | name: 'length', 134 | shortDesc: 'знайти довжину масиву', 135 | desc: 'Повертає кількість елементів у цьому масиві.', 136 | example: `console.log(arr.length);`, 137 | output: `3` 138 | }, 139 | { 140 | name: 'fill', 141 | shortDesc: 'заповнити всі елементи масиву статичним значенням', 142 | desc: 143 | 'Заповнює всі елементи масиву від початкового індексу до кінцевого індексу зі статичним значенням.', 144 | example: `arr.fill(2);
145 | console.log(arr);`, 146 | output: `[2, 2, 2]` 147 | }, 148 | { 149 | name: 'copyWithin', 150 | shortDesc: 'копіювати послідовність елементів масиву в масиві.', 151 | desc: 152 | 'Копіює послідовність елементів масиву в масиві. Ви можете вказати або тільки кінцевий елемент (де початок буде за замовчуванням до нуля) або як початок, так і кінець, розділені комами. ', 153 | example: `arr.copyWithin(1);
154 | console.log(arr);`, 155 | output: `[5, 5, 1]` 156 | } 157 | ], 158 | iterate: [ 159 | { 160 | name: 'forEach', 161 | shortDesc: 'виконуючи функцію, яку я створив для кожного елемента', 162 | desc: 163 | 'Метод forEach () виконує надану функцію один раз для кожного елемента масиву.', 164 | example: `arr.forEach((element) => {
165 |   console.log(element)
166 | });`, 167 | output: `5
168 | 1
169 | 8` 170 | }, 171 | { 172 | name: 'map', 173 | shortDesc: 174 | 'створення нового масиву з кожного елемента з функцією, яку я створюю', 175 | desc: 176 | 'Створює новий масив з результатами виклику передбаченої функції на кожен елемент цього масиву.', 177 | example: `let map = arr.map(x => x + 1);
178 | console.log(map);`, 179 | output: `[6, 2, 9]` 180 | }, 181 | { 182 | name: 'entries', 183 | shortDesc: `створення об'єкта ітератора`, 184 | desc: 185 | `Повертає новий об'єкт Array Iterator, який містить пари ключ / значення для кожного індексу в масиві. Для ітераторів існує безліч застосувань, а також інші способи, що використовуються разом з ним, як, наприкладvalues та keys`, 186 | example: `let iterator = arr.entries();
187 | console.log(iterator.next().value);`, 188 | output: `[0, 5]
189 | // 0 це індекс,
190 | // 5 значення за індексом` 191 | } 192 | ], 193 | find: { 194 | single: [ 195 | { 196 | name: 'includes', 197 | shortDesc: 'чи певний елемент існує', 198 | desc: 199 | 'Визначає, чи містить масив певний елемент, при необхідності повертаючи true або false.', 200 | example: `console.log(arr.includes(1));`, 201 | output: `true` 202 | }, 203 | { 204 | name: 'indexOf', 205 | shortDesc: 'перший індекс певного елемента', 206 | desc: 207 | 'Повертає перший індекс, за яким даний елемент може бути знайдено в масиві, або -1, якщо його немає.', 208 | example: `console.log(arr.indexOf(5));`, 209 | output: `0` 210 | }, 211 | { 212 | name: 'lastIndexOf', 213 | shortDesc: 'останній індекс конкретного елемента', 214 | desc: 215 | 'Повертає останній (найбільший) індекс елемента в масиві, який дорівнює вказаному значенню, або -1, якщо нічого не знайдено.', 216 | example: `console.log(arr.lastIndexOf(5));`, 217 | output: `0` 218 | }, 219 | { 220 | name: 'find', 221 | shortDesc: 'перший елемент, який задовольняє умовам', 222 | desc: 223 | 'Повертає знайдене значення в масиві, якщо елемент у масиві задовольняє надану функцію тестування або не визначено, якщо не знайдено. Схожий наfindIndex(), але він повертає елемент замість індексу.', 224 | example: `let isTiny = (el) => el < 2;
225 | console.log(arr.find(isTiny));`, 226 | output: `1` 227 | }, 228 | { 229 | name: 'findIndex', 230 | shortDesc: 'перший індекс елемента, який задовольняє умовам', 231 | desc: 232 | 'Повертає індекс першого елемента в масиві, який задовольняє надану функцію тестування. В іншому випадку -1 повертається. Схожий наfind(), але він повертає індекс замість елементу.', 233 | example: `let isBig = (el) => el > 6;
234 | console.log(arr.findIndex(isBig));`, 235 | output: `2` 236 | }, 237 | { 238 | name: 'reduce', 239 | shortDesc: 'значення за допомогою зменшення масиву, від початку до закінчення', 240 | desc: 241 | 'Застосувати функцію до акумулятора та кожного значення масиву (зліва направо), щоб зменшити його до одного значення.', 242 | example: `let reducer = (a, b) => a + b;
243 | console.log(arr.reduce(reducer));`, 244 | output: `14` 245 | }, 246 | { 247 | name: 'reduceRight', 248 | shortDesc: 'значення за допомогою зменшення масиву, від закінчення до початку', 249 | desc: 250 | 'Застосувати функцію проти акумулятора та кожного значення масиву (справа наліво), щоб зменшити його до одного значення.', 251 | example: `[arr, [0, 1]].reduceRight((a, b) => {
252 |   return a.concat(b)
253 | }, [])`, 254 | output: `[0, 1, 5, 1, 8]` 255 | } 256 | ], 257 | many: [ 258 | { 259 | name: 'filter', 260 | shortDesc: 'значення на основі умови яку я створюю', 261 | desc: 262 | 'Створює новий масив з усіма елементами цього масиву, для якого надана функція фільтрування повертає true.', 263 | example: `let filtered = arr.filter(el => el > 4);
264 | console.log(filtered)`, 265 | output: `[5, 8]` 266 | }, 267 | { 268 | name: 'every', 269 | shortDesc: 'чи не кожен елемент задовольняє умовам', 270 | desc: 271 | 'Повертає true, якщо кожен елемент цього масиву задовольняє надану функцію тестування.', 272 | example: `let isSmall = (el) => el < 10;
273 | console.log(arr.every(isSmall));`, 274 | output: `true` 275 | }, 276 | { 277 | name: 'some', 278 | shortDesc: 'чи принаймні один предмет задовольняє умовам', 279 | desc: 280 | 'Повертає true, якщо принаймні один елемент цього масиву задовольняє надану функцію тестування.', 281 | example: `let biggerThan4 = (el) => el > 4;
282 | console.log(arr.some(biggerThan4));`, 283 | output: `true` 284 | } 285 | ] 286 | } 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /src/store/zh_cn.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | state: { 3 | selectedMethod: '', 4 | adding: [ 5 | { 6 | name: 'splice', 7 | shortDesc: '一个或多个元素到数组', 8 | desc: '添加、删除或替换数组中的元素。', 9 | example: `arr.splice(2, 0, 'tacos');
10 | console.log(arr);`, 11 | output: `[5, 1, 'tacos', 8]` 12 | }, 13 | { 14 | name: 'push', 15 | shortDesc: '元素到数组的末尾', 16 | desc: 17 | '将一个或多个元素添加到数组的末尾,并返回数组的新长度。', 18 | example: `arr.push(2);
19 | console.log(arr);`, 20 | output: '[5, 1, 8, 2]' 21 | }, 22 | { 23 | name: 'unshift', 24 | shortDesc: '元素到数组的开头', 25 | desc: 26 | '将一个或多个元素添加到数组的开头,并返回数组的新长度。', 27 | example: `arr.unshift(2, 7);
28 | console.log(arr);`, 29 | output: '[2, 7, 5, 1, 8]' 30 | }, 31 | { 32 | name: 'concat', 33 | shortDesc: '其他数组或值到这个数组', 34 | desc: 35 | '返回由这个数组与其他数组或值组成的新数组。', 36 | example: `let arr2 = ['a', 'b', 'c'];
37 | let arr3 = arr.concat(arr2);
38 | console.log(arr3);`, 39 | output: `[5, 1, 8, 'a', 'b', 'c']` 40 | } 41 | ], 42 | removing: [ 43 | { 44 | name: 'splice', 45 | shortDesc: '数组中一个或多个元素', 46 | desc: '添加、删除或替换数组中的元素。', 47 | example: `arr.splice(2, 1);
48 | console.log(arr);`, 49 | output: `[5, 1]` 50 | }, 51 | { 52 | name: 'pop', 53 | shortDesc: '数组的最后一个元素', 54 | desc: 55 | '从数组中删除最后一个元素并返回该元素。', 56 | example: `arr.pop();
57 | console.log(arr);`, 58 | output: `[5, 1]` 59 | }, 60 | { 61 | name: 'shift', 62 | shortDesc: '数组的第一个元素', 63 | desc: 64 | '从数组中移除第一个元素并返回该元素。', 65 | example: `arr.shift();
66 | console.log(arr);`, 67 | output: `[1, 8]` 68 | }, 69 | { 70 | name: 'slice', 71 | shortDesc: 72 | '一个或多个才能使用,保持原数组不变。', 73 | desc: 74 | 'slice()方法返回一个新的数组,是对原数组部分的浅拷贝。可以只传入 begin 开始位置参数( end 结束位置将默认为数组的长度),或者都传入 slice(begin, end) 。原数组不会被修改。', 75 | example: `let slicedArr = arr.slice(1);
76 | console.log(arr);
77 | console.log(slicedArr);`, 78 | output: `[5, 1, 8]
79 | [1, 8]` 80 | } 81 | ], 82 | string: [ 83 | { 84 | name: 'join', 85 | shortDesc: '把数组中的所有元素转换为字符串', 86 | desc: `把数组中的所有元素转换为字符串。可以按原样,或者在中间加入elements.join('-')返回foo-bar`, 87 | example: `console.log(arr.join());`, 88 | output: `"5,1,8"` 89 | }, 90 | { 91 | name: 'toString', 92 | shortDesc: '返回一个表示数组的字符串。', 93 | desc: '返回表示数组和它元素的字符串。', 94 | example: `console.log(arr.toString());`, 95 | output: `"5,1,8"` 96 | }, 97 | { 98 | name: 'toLocaleString', 99 | shortDesc: '返回表示该数组的本地化字符串。', 100 | desc: 101 | '这个有点怪。返回表示数组及其元素的本地化字符串。这对日期和货币是非常有用,有一些奇怪的原生抽象,所以最好使用时参考文档。', 102 | example: `let date = [new Date()];
103 | const arrString = arr.toLocaleString();
104 | const dateString = date.toLocaleString();
105 | console.log(arrString, dateString);`, 106 | output: `"5,1,8 12/26/2017, 6:54:49 PM"` 107 | } 108 | ], 109 | ordering: [ 110 | { 111 | name: 'reverse', 112 | shortDesc: '反转数组中的元素顺序。', 113 | desc: 114 | '反转数组中元素的顺序 - 第一个变成最后一个,最后一个变成第一个。', 115 | example: `arr.reverse();
116 | console.log(arr);`, 117 | output: `[8, 1, 5]` 118 | }, 119 | { 120 | name: 'sort', 121 | shortDesc: '对数组中元素进行排序。', 122 | desc: `对数组中的元素进行排序并返回数组。
123 |
124 | 注意:如果没有给出用于比较的函数,数组中的元素会被转换成字符串后再比较,然后以 Unicode 的顺序进行排序。在对数字进行排序的时候,9 本来应该排在 80 前面,但因为数字会被转换成字符串,而按照 Unicode 的顺序,“80”会排在“9”前面。详细信息可查看文档。`, 125 | example: `arr.sort();
126 | console.log(arr);`, 127 | output: `[1, 5, 8]` 128 | } 129 | ], 130 | other: [ 131 | { 132 | name: 'length', 133 | shortDesc: '查询数组的长度', 134 | desc: '返回数组中元素的数目。', 135 | example: `console.log(arr.length);`, 136 | output: `3` 137 | }, 138 | { 139 | name: 'fill', 140 | shortDesc: '用静态值填充数组的所有元素', 141 | desc: 142 | '用一个静态值从开始索引到结束索引填充数组的所有元素。', 143 | example: `arr.fill(2);
144 | console.log(arr);`, 145 | output: `[2, 2, 2]` 146 | }, 147 | { 148 | name: 'copyWithin', 149 | shortDesc: '复制数组中的一系列数组元素。', 150 | desc: 151 | '复制数组中的一系列数组元素。可以只传入 end 结束位置参数( begin 开始位置将默认为 0),或者都传入 copyWithin(begin, end) ', 152 | example: `arr.copyWithin(1);
153 | console.log(arr);`, 154 | output: `[5, 5, 1]` 155 | } 156 | ], 157 | iterate: [ 158 | { 159 | name: 'forEach', 160 | shortDesc: '为每个元素都执行一次回调函数。', 161 | desc: 162 | 'The forEach() 方法为每个元素都执行一次回调函数。', 163 | example: `arr.forEach((element) => {
164 |   console.log(element)
165 | });`, 166 | output: `5
167 | 1
168 | 8` 169 | }, 170 | { 171 | name: 'map', 172 | shortDesc: 173 | '回调函数处理每个元素并利用返回一个新数组', 174 | desc: 175 | '通过指定函数处理数组的每个元素,并返回处理后的数组。', 176 | example: `let map = arr.map(x => x + 1);
177 | console.log(map);`, 178 | output: `[6, 2, 9]` 179 | }, 180 | { 181 | name: 'entries', 182 | shortDesc: '创建一个迭代器对象', 183 | desc: 184 | 'entries() 返回一个遍历器对象,用来遍历[键名, 键值]组成的数组。迭代器有很多用途,还有其他与之结合使用的方法,如valueskeys方法', 185 | example: `let iterator = arr.entries();
186 | console.log(iterator.next().value);`, 187 | output: `[0, 5]
188 | // the 0 is the index,
189 | // the 5 is the first number` 190 | } 191 | ], 192 | find: { 193 | single: [ 194 | { 195 | name: 'includes', 196 | shortDesc: '某个元素是否存在', 197 | desc: 198 | '确定数组是否包含某个元素,并根据需要返回true或false。', 199 | example: `console.log(arr.includes(1));`, 200 | output: `true` 201 | }, 202 | { 203 | name: 'indexOf', 204 | shortDesc: '给定元素的第一个索引', 205 | desc: 206 | '返回数组中可以找到给定元素的第一个索引,如果不存在则返回-1。', 207 | example: `console.log(arr.indexOf(5));`, 208 | output: `0` 209 | }, 210 | { 211 | name: 'lastIndexOf', 212 | shortDesc: '给定元素的最后一个索引', 213 | desc: 214 | '返回一个给定元素最后出现的位置,如果不存在则返回-1。', 215 | example: `console.log(arr.lastIndexOf(5));`, 216 | output: `0` 217 | }, 218 | { 219 | name: 'find', 220 | shortDesc: '满足条件的第一个元素', 221 | desc: 222 | '如果数组中的元素满足提供的回调函数,则返回数组中找到的值。如果未找到,则返回undefined。类似于findIndex(),但它返回的是项目而不是索引。', 223 | example: `let isTiny = (el) => el < 2;
224 | console.log(arr.find(isTiny));`, 225 | output: `1` 226 | }, 227 | { 228 | name: 'findIndex', 229 | shortDesc: '满足条件的第一个元素的索引', 230 | desc: 231 | '返回数组中满足提供的回调函数的第一个元素的索引,否则返回-1,与 find() 类似,但它返回索引而不是项目。', 232 | example: `let isBig = (el) => el > 6;
233 | console.log(arr.findIndex(isBig));`, 234 | output: `2` 235 | }, 236 | { 237 | name: 'reduce', 238 | shortDesc: '从头到尾将数组元素计算为一个值', 239 | desc: 240 | '接收一个函数作为累加器,数组中的每个值(从左到右)开始缩减,最终计算为一个值。', 241 | example: `let reducer = (a, b) => a + b;
242 | console.log(arr.reduce(reducer));`, 243 | output: `14` 244 | }, 245 | { 246 | name: 'reduceRight', 247 | shortDesc: '从尾到头将数组元素计算为一个值。', 248 | desc: 249 | '接收一个函数作为累加器,数组中的每个值(从右到左)开始缩减,最终计算为一个值。', 250 | example: `[arr, [0, 1]].reduceRight((a, b) => {
251 |   return a.concat(b)
252 | }, [])`, 253 | output: `[0, 1, 5, 1, 8]` 254 | } 255 | ], 256 | many: [ 257 | { 258 | name: 'filter', 259 | shortDesc: '返回符合条件所有元素的数组', 260 | desc: 261 | '创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素。', 262 | example: `let filtered = arr.filter(el => el > 4);
263 | console.log(filtered)`, 264 | output: `[5, 8]` 265 | }, 266 | { 267 | name: 'every', 268 | shortDesc: '每个元素是否都符合条件', 269 | desc: 270 | '如果数组中的每个元素满足指定函数,则返回true。', 271 | example: `let isSmall = (el) => el < 10;
272 | console.log(arr.every(isSmall));`, 273 | output: `true` 274 | }, 275 | { 276 | name: 'some', 277 | shortDesc: '至少有一个元素符合指定条件', 278 | desc: 279 | '如果数组中的至少一个元素满足指定函数,则返回true。', 280 | example: `let biggerThan4 = (el) => el > 4;
281 | console.log(arr.some(biggerThan4));`, 282 | output: `true` 283 | } 284 | ] 285 | } 286 | } 287 | } 288 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | const test = require('tape') 2 | const options = require('./src/options') 3 | 4 | const isObject = prop => 5 | !Array.isArray(prop) && prop !== null && typeof prop === 'object' 6 | 7 | test('en:', t => { 8 | let lang = 'en' 9 | 10 | let state = require('./src/store')[lang].state 11 | let questions = options(lang) 12 | 13 | const findQuestion = name => questions.find(obj => obj.name === name) 14 | const getOptions = name => state[name].map(s => s.shortDesc) 15 | 16 | test('initial', t => { 17 | t.plan(3) 18 | 19 | let question = findQuestion('init') 20 | 21 | t.deepEqual(question.name, 'init', 'name should be init ') 22 | 23 | t.deepEqual( 24 | question.message, 25 | 'I have an array, I would like to', 26 | 'displays appropriate message' 27 | ) 28 | 29 | t.deepEqual( 30 | question.choices, 31 | [ 32 | 'add items or other arrays', 33 | 'remove items', 34 | 'find items', 35 | 'walk over items', 36 | 'return a string', 37 | 'order an array', 38 | 'something else' 39 | ], 40 | 'displays the right choices' 41 | ) 42 | }) 43 | 44 | test('adding', t => { 45 | t.plan(3) 46 | 47 | let name = 'adding' 48 | 49 | let question = findQuestion(name) 50 | 51 | t.deepEqual(question.name, name, 'name should be ' + name) 52 | 53 | t.deepEqual( 54 | question.message, 55 | 'I need to add', 56 | 'displays appropriate message' 57 | ) 58 | 59 | t.deepEqual( 60 | question.choices, 61 | getOptions(name), 62 | 'displays the right choices' 63 | ) 64 | }) 65 | 66 | test('removing', t => { 67 | t.plan(3) 68 | 69 | let name = 'removing' 70 | 71 | let question = findQuestion(name) 72 | 73 | t.deepEqual(question.name, name, 'name should be ' + name) 74 | 75 | t.deepEqual( 76 | question.message, 77 | 'I need to remove', 78 | 'displays appropriate message' 79 | ) 80 | 81 | t.deepEqual( 82 | question.choices, 83 | getOptions(name), 84 | 'displays the right choices' 85 | ) 86 | }) 87 | 88 | test('string', t => { 89 | t.plan(3) 90 | 91 | let name = 'string' 92 | 93 | let question = findQuestion(name) 94 | 95 | t.deepEqual(question.name, name, 'name should be ' + name) 96 | 97 | t.deepEqual(question.message, 'I need to', 'displays appropriate message') 98 | 99 | t.deepEqual( 100 | question.choices, 101 | getOptions(name), 102 | 'displays the right choices' 103 | ) 104 | }) 105 | 106 | test('ordering', t => { 107 | t.plan(3) 108 | 109 | let name = 'ordering' 110 | 111 | let question = findQuestion(name) 112 | 113 | t.deepEqual(question.name, name, 'name should be ' + name) 114 | 115 | t.deepEqual(question.message, 'I need to', 'displays appropriate message') 116 | 117 | t.deepEqual( 118 | question.choices, 119 | getOptions(name), 120 | 'displays the right choices' 121 | ) 122 | }) 123 | 124 | test('other', t => { 125 | t.plan(3) 126 | 127 | let name = 'other' 128 | 129 | let question = findQuestion(name) 130 | 131 | t.deepEqual(question.name, name, 'name should be ' + name) 132 | 133 | t.deepEqual(question.message, 'I need to', 'displays appropriate message') 134 | 135 | t.deepEqual( 136 | question.choices, 137 | getOptions(name), 138 | 'displays the right choices' 139 | ) 140 | }) 141 | 142 | test('iterate', t => { 143 | t.plan(3) 144 | 145 | let name = 'iterate' 146 | 147 | let question = findQuestion(name) 148 | 149 | t.deepEqual(question.name, name, 'name should be ' + name) 150 | 151 | t.deepEqual( 152 | question.message, 153 | 'I need to iterate by', 154 | 'displays appropriate message' 155 | ) 156 | 157 | t.deepEqual( 158 | question.choices, 159 | getOptions(name), 160 | 'displays the right choices' 161 | ) 162 | }) 163 | 164 | test('find', t => { 165 | t.plan(3) 166 | 167 | let name = 'find' 168 | 169 | let question = findQuestion(name) 170 | 171 | t.deepEqual(question.name, name, 'name should be ' + name) 172 | 173 | t.deepEqual( 174 | question.message, 175 | "I'm trying to find", 176 | 'displays appropriate message' 177 | ) 178 | 179 | t.deepEqual( 180 | question.choices, 181 | ['one item', 'one or many items'], 182 | 'displays the right choices' 183 | ) 184 | }) 185 | 186 | t.end() 187 | }) 188 | 189 | test('others:', t => { 190 | Object.keys(require('./src/locale')).map(lang => { 191 | test(lang + ' works', t => { 192 | t.plan(2) 193 | 194 | let state = require('./src/store')[lang].state 195 | let questions = options(lang) 196 | 197 | t.equal(isObject(state), true) 198 | t.equal(Array.isArray(questions), true) 199 | }) 200 | }) 201 | t.end() 202 | }) 203 | --------------------------------------------------------------------------------