Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hw20 #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

hw20 #31

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions js-core/homeworks/homework-20/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home work 1</title>
</head>
<body>

<script src="src/main.js"></script>
</body>
</html>
43 changes: 43 additions & 0 deletions js-core/homeworks/homework-20/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Алгоритмы
TASK 0
Проверьте 2 строки и определите изоморфные ли они.
Две строки являются изоморфными если все их символы
s, могут быть заменены t.
Все символы одной строки могут быть заменены такими же символами другой строки, независимо от
порядка символов.
Given two strings, determine if they are isomorphic.
Two strings are isomorphic if the characters in s can be replaced to get t.
All occurrences of a character must be replaced with another character while preserving the order of characters.
No two characters may map to the same character but a character may map to itself."
arguments ["egg", "add"] => expected true
arguments ["foo", "bar"] => expected false
arguments ["paper", "title"] => expected true
arguments ["ca", "ab"] => expected true
arguments ["aa", "bb"] => expected true
arguments ["aedor", "eiruw"] => expected true
*/

var arguments = (arr) => {
let first = arr[0];
let second = arr[1];
let obj = {};
if (first.length != second.length) {
console.log(`1 `, 'expected false');
}
for (let i = 0; i < first.length; i++) {
if (obj[first.charAt(i)] == undefined) {
obj[first.charAt(i)] = second.charAt(i)
} else if (obj[first.charAt(i)] != second.charAt(i)) {
console.log(`2 `, 'expected false');
return;
}

}
console.log('expected true');
}
arguments(["egg", "add"]);
arguments(["foo", "bar"]);
arguments(["paper", "title"]);
arguments(["ca", "ab"]);
arguments(["aa", "bh"]);
arguments(["aedor", "eiruw"]);