==
vuejs task
write the reoraderable list component . the component should recieve an array of elements as items prop and should displa the elements as list items in an unorderseed list
when the user click on a list item it should be sent to the first positionin the unordered list
for example if the component has the item prop ["A","B","C"], the list should look like:
<!DOCTYPE html>
<html>
<head>
<title>Reorderable List</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
</head>
<body>
<div id="app">
<reorderable-list :items="['A', 'B', 'C']"></reorderable-list>
</div>
<script>
Vue.component('reorderable-list', {
props: ['items'],
data() {
return {
list: [...this.items]
};
},
methods: {
moveToFirst(index) {
const item = this.list.splice(index, 1)[0];
this.list.unshift(item);
}
},
template: `
<ul>
<li v-for="(item, index) in list" :key="index" @click="moveToFirst(index)">
{{ item }}
</li>
</ul>
`
});
new Vue({
el: '#app'
});
</script>
</body>
</html>
==
second task
convert a string of numbers to a sentnce .e ach number represents a aletter. numbers in the string are seperated by aspace. and words in the sentence are seperated by a plus characterf/
conversion table:
1 = A
2 =B
--
26 = Z
example numbe to letters (`20 15 19 20+4 15 13 5) should return 'test dome'
<?php
function numberToLetters($string)
{
$conversionTable = [
1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D', 5 => 'E', 6 => 'F', 7 => 'G', 8 => 'H', 9 => 'I', 10 => 'J',
11 => 'K', 12 => 'L', 13 => 'M', 14 => 'N', 15 => 'O', 16 => 'P', 17 => 'Q', 18 => 'R', 19 => 'S',
20 => 'T', 21 => 'U', 22 => 'V', 23 => 'W', 24 => 'X', 25 => 'Y', 26 => 'Z'
];
$words = explode('+', $string); // Split string into words separated by '+'
$result = [];
foreach ($words as $word) {
$letters = explode(' ', $word); // Split each word into numbers separated by spaces
$wordResult = '';
foreach ($letters as $number) {
if (isset($conversionTable[$number])) {
$wordResult .= $conversionTable[$number];
}
}
$result[] = $wordResult;
}
return strtolower(implode(' ', $result)); // Convert result to a sentence in lowercase
}
// Example usage
echo numberToLetters('20 5 19 20+4 15 13 5'); // Outputs: test dome
?>
echo numberToLetters('20 5 19 10+4 15 13 5');
===============================
implement the get view count method .it should accept a json
a string and sum all vie wcount fields inside the json will alwyas hav ethe same structure as int he example case
for example calling get view count should return 88270796 for the following $jsonstring
{
"apiVersion": "2.1",
"videos": [
{
"id": "253",
"category": "music",
"title": "Jingle Bells",
"duration": 457,
"viewCount": 88270796
}
]
}
==
<?php
function getViewCount(string $jsonString): int
{
$data = json_decode($jsonString, true);
$totalViewCount = 0;
if (isset($data['videos']) && is_array($data['videos'])) {
foreach ($data['videos'] as $video) {
if (isset($video['viewCount'])) {
$totalViewCount += $video['viewCount'];
}
}
}
return $totalViewCount;
}
$jsonString = '
{
"apiVersion": "2.1",
"videos": [
{
"id": "253",
"category": "music",
"title": "Jingle Bells",
"duration": 457,
"viewCount": 88270796
}
]
}
';
echo getViewCount($jsonString);
?>
===
writea a function that removes all items that are not integers from the array the function should modify the existing aarray,nmot create a nbew one.
for example, if the input array containes values [1,'a,'b',2], after processing, the array will contain only values [1,2]
<?php
function filterNumbersFromArray(array &$arr): void
{
foreach ($arr as $key => $value) {
if (!is_int($value)) {
unset($arr[$key]);
}
}
}
$arr = [1, 'a', 'b', 2];
filterNumbersFromArray($arr);
print_r(array_values($arr));
?>
==============
an education magazine pulbishee rankings of strudnetns and theire colleges in a acompetitoion in building unmmaned aerial vehical dornes. students whoi participated in the competion in different yeres, their ranking in the competion, and their colleges are contained inthe following tables;
table colleges
id integer primary key
name varchar(50) not null
table students
id integer primary key
name varchar(50) not null
collegeid integer
foreighn key (collegeid) references colleges(id)
table rankings
studentid integer
ranking integer not null
year integer not null
foreign key (studentid) references students(id)
write a query that lists all collges that have atleast one student with a ranking between 1 and 3 ( both inclusive) for the year 2015. the query should return
the college name,
the rank of their best rnaking studnet for 21015.;
the numer of students who had rankings between 1 and 3 ( both inclusive) for the year 2015
rank 1 is the best rank, rank 2 is the second best an dso on . more than one student can tie for a rank in a ayear
SELECT
c.name AS college_name,
MIN(r.ranking) AS best_rank_2015,
COUNT(*) AS num_students_rank_1_to_3
FROM
rankings r
JOIN
students s ON r.studentid = s.id
JOIN
colleges c ON s.collegeid = c.id
WHERE
r.year = 2015
AND r.ranking BETWEEN 1 AND 3
GROUP BY
c.name;
=
=
As part of a data processing pipeline, complete the implementation of the make_pipeline method:
- The make_pipeline method should accept a variable number of functions, and it should return a new function that accepts one parameter $arg.
- The returned function should call the first function in make_pipeline with the parameter $arg, and call the second function with the result of the first function.
- The returned function should continue calling each function in make_pipeline in order, following the same pattern, and return the value from the last function.
For example, calling make_pipeline(function($x) { return $x * 3; }, function($x) { return $x + 1; }, function($x) { return $x / 2; }), and then calling the returned function with 3 should return 5.
<?php
function make_pipeline(...$funcs)
{
return function ($arg) use ($funcs) {
$result =$arg;
foreach ($funcs as $func){
$result = $func($result);
}
return $result;
};
}
$fun = make_pipeline(
function ($x) {
return $x * 3;
},
function ($x) {
return $x + 1;
},
function ($x) {
return $x / 2;
}
);
echo $fun(3); # should print 5
===
App usage data are kept in the following table:
TABLE sessions
id INTEGER PRIMARY KEY,
userId INTEGER NOT NULL,
duration DECIMAL NOT NULL
Write a query that selects userId and average session duration for each user who has more than one session.
SELECT userid, AVG(duration) AS avg_duration
FROM sessions
GROUP BY userid
HAVING COUNT(id) > 1;
=
questions:
what is abstract and what is interface
why we use abstaract
what is difference
why do we interface
wht is static method
where can use static, where can we declare static
solid principles
design pattern
whtis service container and service provider
array methods
what type of array in php supports
session and cookie
what is http only cookie
what is break and continue
how can we handle exceptions
what is finally in php
whatr is composer
what is composer.lock
how to update the pacakge
how can we update teh specific pakage
life cycke method in vuejs
how to bind the data
what is v-model
event emitters
what is props and data functions
hwo can we declare a method in vuejs
what is pure function in javascript
set time out and set interval
how to stop the setinterval
hosting in javascript
waht is closure in javacript
sql
what are join in sql
what is self join
what is inner join
what is group by
what is indexing mechanism
what is composite index
aany experience in version control system and what is the workf low