forked from AdamMomen/warmUp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
warmUp18.js
32 lines (28 loc) · 848 Bytes
/
warmUp18.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// You are given an input string.
// For each symbol in the string if it's the first character occurence, replace it with a '1', else replace it with the amount of times you've already seen it...
// But will your code be performant enough?
// Examples:
// input = "Hello, World!"
// result = "1112111121311"
// input = "aaaaaaaaaaaa"
// result = "123456789101112"
function replaceString(str) {
var arr = str.split('');
var letters = [];
var result = [];
for (var i = 0; i < arr.length; i++) {
var count = 1;
console.log(letters.indexOf(arr[i]), arr[i], result , 'first')
if (letters.indexOf(arr[i]) != -1) {
console.log(count, 'second')
for (var i = 0; i < letters.length; i++) {
if (letters[i] === arr[i]) {
count++
}
}
}
letters.push(arr[i])
result.push(count)
}
return result
}