Created
January 15, 2019 21:57
-
-
Save Dmitriy-8-Kireev/f0dbc1a3b882d6d584513665e47e65d9 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/vozusih
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
/** | |
* Получения двумерный массив анаграмм из произвольного массива слов | |
* @param {string[]} list | |
* @returns {Array<[string, string]>} | |
*/ | |
function getAnagrams(list) { | |
let arr = []; | |
let origin = list.map(x => x.split('').sort().join('')); | |
for (let i = 0; i < origin.length; i++) { | |
if (list[i] != list[i+1+origin.slice(i+1).indexOf(origin[i])]) { | |
arr.push([list[i], list[i+1+origin.slice(i+1).indexOf(origin[i])]]); | |
} | |
} | |
return arr | |
} | |
const inputList = [ | |
'кот', 'пила', 'барокко', | |
'стоп', 'ток', 'кошка', | |
'липа', 'коробка', 'пост', | |
]; | |
console.log(getAnagrams(inputList)) | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">/** | |
* Получения двумерный массив анаграмм из произвольного массива слов | |
* @param {string[]} list | |
* @returns {Array<[string, string]>} | |
*/ | |
function getAnagrams(list) { | |
let arr = []; | |
let origin = list.map(x => x.split('').sort().join('')); | |
for (let i = 0; i < origin.length; i++) { | |
if (list[i] != list[i+1+origin.slice(i+1).indexOf(origin[i])]) { | |
arr.push([list[i], list[i+1+origin.slice(i+1).indexOf(origin[i])]]); | |
} | |
} | |
return arr | |
} | |
const inputList = [ | |
'кот', 'пила', 'барокко', | |
'стоп', 'ток', 'кошка', | |
'липа', 'коробка', 'пост', | |
]; | |
console.log(getAnagrams(inputList))</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Получения двумерный массив анаграмм из произвольного массива слов | |
* @param {string[]} list | |
* @returns {Array<[string, string]>} | |
*/ | |
function getAnagrams(list) { | |
let arr = []; | |
let origin = list.map(x => x.split('').sort().join('')); | |
for (let i = 0; i < origin.length; i++) { | |
if (list[i] != list[i+1+origin.slice(i+1).indexOf(origin[i])]) { | |
arr.push([list[i], list[i+1+origin.slice(i+1).indexOf(origin[i])]]); | |
} | |
} | |
return arr | |
} | |
const inputList = [ | |
'кот', 'пила', 'барокко', | |
'стоп', 'ток', 'кошка', | |
'липа', 'коробка', 'пост', | |
]; | |
console.log(getAnagrams(inputList)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment