Нужда от малко помощ относно Джава скрипт

  • 1 714
  • 9
Здравейте!

Моля за помощ всеки, който има поглед над този програмен език! :Pray:

Става въпрос за Джава Скрипт.  Ще пусна една задача, ако някой може да даде решение, благодаря!

По-важното е обаче да дадете мнение за трудността на задачата. Също така и след каква продължителност на обучение може да се очаква да може човек да решава такива задачи?
Защото са казали на сина ми, че след месец трябва вече да има пълно разбиране за езика и да може да решава такива задачи. А той ги намира за много трудни на този етап (след 2 месеца самообучение).

Ето задачата в общия й смисъл. Текстът е много по-дълъг, но това не е от значение. Занятието си остава същото.

Copy the text from text.txt and:
• A) sort words found in the text and print them in the console
• B) count each word frequency and print them in the console in following format <word>:<count>, each record should be in new line.

Това е откъс от въпросния текст:

The last question was asked for the first time, half in jest, on May 21, 2061, at a time when humanity first stepped into the light. The question came about as a result of a five-dollar bet over highballs, and it happened this way:
    Alexander Adell and Bertram Lupov were two of the faithful attendants of Multivac. As well as any human beings could, they knew what lay behind the cold, clicking, flashing face -- miles and miles of face -- of that giant computer. They had at least a vague notion of the general plan of relays and circuits that had long since grown past the point where any single human could possibly have a firm grasp of the whole.
     Multivac was self-adjusting and self-correcting. It had to be, for nothing human could adjust and correct it quickly enough or even adequately enough. So Adell and Lupov attended the monstrous giant only lightly and superficially, yet as well as any men could. They fed it data, adjusted questions to its needs and translated the answers that were issued. Certainly they, and all others like them, were fully entitled to share in the glory that was Multivac's.
     For decades, Multivac had helped design the ships and plot the trajectories that enabled man to reach the Moon, Mars, and Venus, but past that, Earth's poor resources could not support the ships. Too much energy was needed for the long trips. Earth exploited its coal and uranium with increasing efficiency, but there was only so much of both.
     But slowly Multivac learned enough to answer deeper questions more fundamentally, and on May 14, 2061, what had been theory, became fact.
     The energy of the sun was stored, converted, and utilized directly on a planet-wide scale. All Earth turned off its burning coal, its fissioning uranium, and flipped the switch that connected all of it to a small station, one mile in diameter, circling the Earth at half the distance of the Moon. All Earth ran by invisible beams of sunpower.
     Seven days had not sufficed to dim the glory of it and Adell and Lupov finally managed to escape from the public functions, and to meet in quiet where no one would think of looking for them, in the deserted underground chambers, where portions of the mighty buried body of Multivac showed. Unattended, idling, sorting data with contented lazy clickings, Multivac, too, had earned its vacation and the boys appreciated that. They had no intention, originally, of disturbing it.
     They had brought a bottle with them, and their only concern at the moment was to relax in the company of each other and the bottle.
     "It's amazing when you think of it," said Adell. His broad face had lines of weariness in it, and he stirred his drink slowly with a glass rod, watching the cubes of ice slur clumsily about. "All the energy we can possibly ever use for free. Enough energy, if we wanted to draw on it, to melt all Earth into a big drop of impure liquid iron, and still never miss the energy so used. All the energy we could ever use, forever and forever and forever."
     Lupov cocked his head sideways. He had a trick of doing that when he wanted to be contrary, and he wanted to be contrary now, partly because he had had to carry the ice and glassware. "Not forever," he said.
     "Oh, hell, just about forever. Till the sun runs down, Bert."
     "That's not forever."
     "All right, then. Billions and billions of years. Ten billion, maybe. Are you satisfied?"

Това е неговия опит за решение до момента. Липсва частта с извеждане на всяка дума и това колко пъти се среща.  Не е стигнал до този момент, защото има проблем с  наличието на нови редове в текста заради което дава грешка.

function sortWords(story) {
var punctDel = story.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"");
var punctZero = punctDel.replace(/\s{2,}/g," ");
var arr = punctZero.split(' ');
var alphabetical = arr.sort();
var frequency = {};
for (var i = 0; i < alphabetical.length; i++) {
var count = alphabetical;
frequency[count] = frequency[count] ? frequency[count] + 1 : 1;
}
return alphabetical;
}

sortWords('The last question was asked for the first time, half in jest, on May 21, 2061, at a time when humanity first stepped into the light. The question came about as a result of a five-dollar bet over highballs, and it happened this way:
    Alexander Adell and Bertram Lupov were two of the faithful attendants of Multivac. As well as any human beings could, they knew what lay behind the cold, clicking, flashing face -- miles and miles of face -- of that giant computer. They had at least a vague notion of the general plan of relays and circuits that had long since grown past the point where any single human could possibly have a firm grasp of the whole.
     Multivac was self-adjusting and self-correcting. It had to be, for nothing human could adjust and correct it quickly enough or even adequately enough. So Adell and Lupov attended the monstrous giant only lightly and superficially, yet as well as any men could. They fed it data, adjusted questions to its needs and translated the answers that were issued. Certainly they, and all others like them, were fully entitled to share in the glory that was Multivac's.
     For decades, Multivac had helped design the ships and plot the trajectories that enabled man to reach the Moon, Mars, and Venus, but past that, Earth's poor resources could not support the ships. Too much energy was needed for the long trips. Earth exploited its coal and uranium with increasing efficiency, but there was only so much of both.
     But slowly Multivac learned enough to answer deeper questions more fundamentally, and on May 14, 2061, what had been theory, became fact.
     The energy of the sun was stored, converted, and utilized directly on a planet-wide scale. All Earth turned off its burning coal, its fissioning uranium, and flipped the switch that connected all of it to a small station, one mile in diameter, circling the Earth at half the distance of the Moon. All Earth ran by invisible beams of sunpower.
     Seven days had not sufficed to dim the glory of it and Adell and Lupov finally managed to escape from the public functions, and to meet in quiet where no one would think of looking for them, in the deserted underground chambers, where portions of the mighty buried body of Multivac showed. Unattended, idling, sorting data with contented lazy clickings, Multivac, too, had earned its vacation and the boys appreciated that. They had no intention, originally, of disturbing it.
     They had brought a bottle with them, and their only concern at the moment was to relax in the company of each other and the bottle.
     \"It's amazing when you think of it,\" said Adell. His broad face had lines of weariness in it, and he stirred his drink slowly with a glass rod, watching the cubes of ice slur clumsily about. \"All the energy we can possibly ever use for free. Enough energy, if we wanted to draw on it, to melt all Earth into a big drop of impure liquid iron, and still never miss the energy so used. All the energy we could ever use, forever and forever and forever.\"
     Lupov cocked his head sideways. He had a trick of doing that when he wanted to be contrary, and he wanted to be contrary now, partly because he had had to carry the ice and glassware. \"Not forever,\" he said.
     \"Oh, hell, just about forever. Till the sun runs down, Bert.\"
     \"That's not forever.\"
     \"All right, then. Billions and billions of years. Ten billion, maybe. Are you satisfied?\"');

Благодаря на всеки, който се отзове! Hug
Виж целия пост
# 1
var punctZero = punctDel.replace тук да добави и новите редове \n
Виж целия пост
# 2
Благодаря! Разбра те! Simple Smile

Може ли да кажеш и нещо относно трудността на задачата?
Виж целия пост
# 3
То беше ли се занимавал с програмиране преди да почне с JS?
Виж целия пост
# 4
То беше ли се занимавал с програмиране преди да почне с JS?

Не, абсолютно никога. Преди два месеца започна от чиста нула. При това положение такава задача следва ли да му бъде трудна, или вече трябваше да е напълно наясно?
Виж целия пост
# 5
Ън, ще ти пиша направо на ЛС по-късно.
Виж целия пост
# 6
Ън, ще ти пиша направо на ЛС по-късно.

Благодаря!
Виж целия пост
# 7
Вече ми е много неудобно, но пак се налага да питам Embarassed
Някаква идея за тази задача на Джава Скрипт?

Трябва да се направи нещо като спортен тотализатор. Трябва да напишеш един клас, който генерира произволни числа в интервала от 1 до 49, и втори клас, който има 2 метода. Единият метод прави тегленето на 6 числа в интервала 1 до 49. Вторият метод взима като аргумент 6 произволни числа (фиш) и проверява дали има някаква печалба. В конзолата трябва да се отпечатат: сортирани, изтеглените числа; сортирани, числата на играча; каква е възможната печалба (т.е. броят на числата на играча, които съвпадат с числата от тегленето).

Благодаря предварително на тези, които дадат идея! Simple Smile
Виж целия пост
# 8
Хъм! Дай оригиналния текст на задачата.
Виж целия пост
# 9
Така е зададена. Изглежда странно.... Rolling Eyes
Виж целия пост

Започнете да пишете...

Страница 1 от 1

Общи условия